mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 17:56:11 +00:00
Test error for -e and ~e when e is potentially nullable
This verifies that the operators `unary-` and `~` do not participate in null-shorting. Cf. https://github.com/dart-lang/language/issues/1081. Change-Id: Iba446724f00c1c4aaedb4be4425e69fb52cdb5c9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166627 Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Commit-Queue: Erik Ernst <eernst@google.com>
This commit is contained in:
parent
34e4a6d814
commit
2d92a26cca
24
tests/language/null_aware/prefix_not_shortening_test.dart
Normal file
24
tests/language/null_aware/prefix_not_shortening_test.dart
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) 2020, 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.
|
||||
|
||||
class C {
|
||||
C e() => this;
|
||||
C operator -() => this;
|
||||
C operator ~() => this;
|
||||
}
|
||||
|
||||
void main() {
|
||||
final C? c = new C();
|
||||
/**/ -c?.e();
|
||||
// ^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
|
||||
// ^
|
||||
// [cfe] Operator 'unary-' cannot be called on 'C?' because it is potentially null.
|
||||
|
||||
/**/ ~c?.e();
|
||||
// ^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
|
||||
// ^
|
||||
// [cfe] Operator '~' cannot be called on 'C?' because it is potentially null.
|
||||
}
|
Loading…
Reference in a new issue