e933e91aaa
This is a reland of 6a1c54ec30
Original change's description:
> Flow analysis: promote to non-nullable on initialization
>
> When flow analysis encounters a variable declaration of the form `T? x
> = expr;`, if the type of `expr` is `T`, then the variable is
> immediately promoted to type `T`.
>
> Fixes #43099.
>
> Change-Id: Ia206fe0d50e2fdd9bdf637e13c85633d8490dbcc
> Bug: https://github.com/dart-lang/sdk/issues/43099
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163841
> Commit-Queue: Paul Berry <paulberry@google.com>
> Reviewed-by: Bob Nystrom <rnystrom@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Bug: https://github.com/dart-lang/sdk/issues/43099
Change-Id: I7530bb0f7c24674a7b500558b89d50b35e045aca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166305
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
118 lines
5.0 KiB
Plaintext
118 lines
5.0 KiB
Plaintext
library /*isNonNullableByDefault*/;
|
|
//
|
|
// Problems in library:
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:14:3: Warning: Operand of null-aware operation '!' has type 'Class' which excludes null.
|
|
// - 'Class' is from 'pkg/front_end/testcases/nnbd/null_check.dart'.
|
|
// c!.field;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:15:3: Warning: Operand of null-aware operation '!' has type 'Class' which excludes null.
|
|
// - 'Class' is from 'pkg/front_end/testcases/nnbd/null_check.dart'.
|
|
// c!.field = 42;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:16:3: Warning: Operand of null-aware operation '!' has type 'Class' which excludes null.
|
|
// - 'Class' is from 'pkg/front_end/testcases/nnbd/null_check.dart'.
|
|
// c!.method;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:17:3: Warning: Operand of null-aware operation '!' has type 'Class' which excludes null.
|
|
// - 'Class' is from 'pkg/front_end/testcases/nnbd/null_check.dart'.
|
|
// c!.method();
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:18:3: Warning: Operand of null-aware operation '!' has type 'Class' which excludes null.
|
|
// - 'Class' is from 'pkg/front_end/testcases/nnbd/null_check.dart'.
|
|
// c!.field!.toString();
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:19:3: Warning: Operand of null-aware operation '!' has type 'Class' which excludes null.
|
|
// - 'Class' is from 'pkg/front_end/testcases/nnbd/null_check.dart'.
|
|
// c!.method()!.toString();
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:20:3: Warning: Operand of null-aware operation '!' has type 'Class' which excludes null.
|
|
// - 'Class' is from 'pkg/front_end/testcases/nnbd/null_check.dart'.
|
|
// c! + c;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:21:3: Warning: Operand of null-aware operation '!' has type 'Class' which excludes null.
|
|
// - 'Class' is from 'pkg/front_end/testcases/nnbd/null_check.dart'.
|
|
// c! + c!;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:21:8: Warning: Operand of null-aware operation '!' has type 'Class' which excludes null.
|
|
// - 'Class' is from 'pkg/front_end/testcases/nnbd/null_check.dart'.
|
|
// c! + c!;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:22:7: Warning: Operand of null-aware operation '!' has type 'Class' which excludes null.
|
|
// - 'Class' is from 'pkg/front_end/testcases/nnbd/null_check.dart'.
|
|
// c + c!;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:23:6: Warning: Operand of null-aware operation '!' has type 'Class' which excludes null.
|
|
// - 'Class' is from 'pkg/front_end/testcases/nnbd/null_check.dart'.
|
|
// (c + c)!;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:26:10: Warning: Operand of null-aware operation '!' has type 'bool' which excludes null.
|
|
// !o! ? !o! : !!o!!;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:26:17: Warning: Operand of null-aware operation '!' has type 'bool' which excludes null.
|
|
// !o! ? !o! : !!o!!;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:26:18: Warning: Operand of null-aware operation '!' has type 'bool' which excludes null.
|
|
// !o! ? !o! : !!o!!;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:27:5: Warning: Operand of null-aware operation '!' has type 'bool' which excludes null.
|
|
// !(o!) ? (!o)! : (!(!o)!)!;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:27:12: Warning: Operand of null-aware operation '!' has type 'bool' which excludes null.
|
|
// !(o!) ? (!o)! : (!(!o)!)!;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:27:22: Warning: Operand of null-aware operation '!' has type 'bool' which excludes null.
|
|
// !(o!) ? (!o)! : (!(!o)!)!;
|
|
// ^
|
|
//
|
|
// pkg/front_end/testcases/nnbd/null_check.dart:27:20: Warning: Operand of null-aware operation '!' has type 'bool' which excludes null.
|
|
// !(o!) ? (!o)! : (!(!o)!)!;
|
|
// ^
|
|
//
|
|
import self as self;
|
|
import "dart:core" as core;
|
|
|
|
class Class extends core::Object {
|
|
field core::int? field = null;
|
|
synthetic constructor •() → self::Class
|
|
: super core::Object::•()
|
|
;
|
|
method method() → core::int?
|
|
return this.{self::Class::field};
|
|
operator +(self::Class other) → self::Class
|
|
return new self::Class::•();
|
|
}
|
|
static method main() → dynamic {
|
|
self::Class? c = new self::Class::•() as{ForNonNullableByDefault} self::Class?;
|
|
c!;
|
|
c{self::Class}!.{self::Class::field};
|
|
c{self::Class}!.{self::Class::field} = 42;
|
|
c{self::Class}!.{self::Class::method};
|
|
c{self::Class}!.{self::Class::method}();
|
|
c{self::Class}!.{self::Class::field}!.{core::int::toString}();
|
|
c{self::Class}!.{self::Class::method}()!.{core::int::toString}();
|
|
c{self::Class}!.{self::Class::+}(c{self::Class});
|
|
c{self::Class}!.{self::Class::+}(c{self::Class}!);
|
|
c{self::Class}.{self::Class::+}(c{self::Class}!);
|
|
c{self::Class}.{self::Class::+}(c{self::Class})!;
|
|
core::bool? o = true as{ForNonNullableByDefault} core::bool?;
|
|
!o! ?{core::bool} !o{core::bool}! : !!o{core::bool}!!;
|
|
!o{core::bool}! ?{core::bool} (!o{core::bool})! : (!(!o{core::bool})!)!;
|
|
}
|