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>
110 lines
1.8 KiB
Dart
110 lines
1.8 KiB
Dart
// TODO(multitest): This was automatically migrated from a multitest and may
|
|
// contain strange or dead code.
|
|
|
|
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// Verify semantics of the ?. operator when it appears in a postincrement or
|
|
// preincrement expression (or a postdecrement or predecrement expression).
|
|
|
|
import "package:expect/expect.dart";
|
|
import "conditional_access_helper.dart" as h;
|
|
|
|
class C {
|
|
int v;
|
|
C(this.v);
|
|
static late int staticInt;
|
|
}
|
|
|
|
class D {
|
|
E v;
|
|
D(this.v);
|
|
static late E staticE;
|
|
}
|
|
|
|
class E {
|
|
G operator +(int i) => new I();
|
|
G operator -(int i) => new I();
|
|
}
|
|
|
|
class F {}
|
|
|
|
class G extends E implements F {}
|
|
|
|
class H {}
|
|
|
|
class I extends G implements H {}
|
|
|
|
C? nullC() => null;
|
|
|
|
main() {
|
|
// Make sure the "none" test fails if assignment to "?." is not implemented.
|
|
// This makes status files easier to maintain.
|
|
nullC()?.v = 1;
|
|
|
|
// e1?.v++ is equivalent to ((x) => x == null ? null : x.v++)(e1).
|
|
|
|
|
|
|
|
// C?.v++ is equivalent to C.v++.
|
|
|
|
|
|
|
|
// The static type of e1?.v++ is the same as the static type of e1.v.
|
|
{ E e1 = new E(); var d = new D(e1) as D?; E? e2 = d?.v++; Expect.identical(e1, e2); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// e1?.v-- is equivalent to ((x) => x == null ? null : x.v--)(e1).
|
|
|
|
|
|
|
|
// C?.v-- is equivalent to C.v--.
|
|
|
|
|
|
|
|
// The static type of e1?.v-- is the same as the static type of e1.v.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ++e1?.v is equivalent to e1?.v += 1.
|
|
|
|
|
|
|
|
// ++C?.v is equivalent to C?.v += 1.
|
|
|
|
|
|
|
|
// The static type of ++e1?.v is the same as the static type of e1.v + 1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --e1?.v is equivalent to e1?.v -= 1.
|
|
|
|
|
|
|
|
// --C?.v is equivalent to C?.v -= 1.
|
|
|
|
|
|
|
|
// The static type of --e1?.v is the same as the static type of e1.v - 1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|