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:
Erik Ernst 2020-10-08 15:01:55 +00:00 committed by commit-bot@chromium.org
parent 34e4a6d814
commit 2d92a26cca

View 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.
}