58ae856422
Bug: https://github.com/dart-lang/sdk/issues/48004 Change-Id: I61c658f9974fdb2023aa999bf34ee873e348058a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/246301 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
69 lines
1.6 KiB
Dart
69 lines
1.6 KiB
Dart
// 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 does not appear on the LHS of an
|
|
// assignment.
|
|
|
|
import "package:expect/expect.dart";
|
|
import "conditional_access_helper.dart" as h;
|
|
|
|
class B {}
|
|
|
|
class C extends B {
|
|
int? v;
|
|
C(this.v);
|
|
static int? staticInt;
|
|
}
|
|
|
|
C? nullC() => null;
|
|
|
|
main() {
|
|
// e1?.id is equivalent to ((x) => x == null ? null : x.id)(e1).
|
|
Expect.equals(null, nullC()?.v);
|
|
|
|
C? c = new C(1) as dynamic;
|
|
Expect.equals(1, c?.v);
|
|
|
|
// C?.id is equivalent to C.id.
|
|
C.staticInt = 1;
|
|
Expect.equals(1, C?.staticInt);
|
|
// ^
|
|
// [cfe] The class 'C' cannot be null.
|
|
// ^^
|
|
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
|
|
|
|
h.C.staticInt = 1;
|
|
Expect.equals(1, h.C?.staticInt);
|
|
// ^
|
|
// [cfe] The class 'C' cannot be null.
|
|
// ^^
|
|
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
|
|
|
|
// The static type of e1?.id is the static type of e1.id.
|
|
{
|
|
int? i = c?.v;
|
|
Expect.equals(1, i);
|
|
}
|
|
|
|
{
|
|
C.staticInt = 1;
|
|
int? i = C?.staticInt;
|
|
// ^
|
|
// [cfe] The class 'C' cannot be null.
|
|
// ^^
|
|
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
|
|
Expect.equals(1, i);
|
|
}
|
|
|
|
{
|
|
h.C.staticInt = 1;
|
|
int? i = h.C?.staticInt;
|
|
// ^
|
|
// [cfe] The class 'C' cannot be null.
|
|
// ^^
|
|
// [analyzer] STATIC_WARNING.INVALID_NULL_AWARE_OPERATOR
|
|
Expect.equals(1, i);
|
|
}
|
|
}
|