5e040a20f8
This changes the span reported from the _receiver_ to the _use_ (method name, property name, operator token). I think this change is overall an improvement. Specifically, its a great improvement for cmdline output, where the receiver and the "use" are on different lines. One possibly weird change is that if the operator is `[]`, then I only highlight the `[` character. I don't know if there is a better place, and I think this is fine. Fixes https://github.com/dart-lang/sdk/issues/43708 Change-Id: Ie66ddf04b4904a367575193106385dd63ee39985 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/188680 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
36 lines
1.2 KiB
Dart
36 lines
1.2 KiB
Dart
// Copyright (c) 2019, 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.
|
|
|
|
|
|
// Test that `x ?? y` results in type LUB(x!, y)
|
|
void main() {
|
|
f1(null, 2);
|
|
}
|
|
|
|
void f1(
|
|
int? nullableInt,
|
|
int nonNullInt,
|
|
) {
|
|
(nullableInt ?? nonNullInt) + 1;
|
|
(nullableInt ?? nullableInt) + 1;
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
|
|
// [cfe] Operator '+' cannot be called on 'int?' because it is potentially null.
|
|
(nonNullInt ?? nullableInt) + 1;
|
|
// ^
|
|
// [cfe] Operand of null-aware operation '??' has type 'int' which excludes null.
|
|
// ^^^^^^^^^^^
|
|
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
|
|
// ^
|
|
// [analyzer] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
|
|
// [cfe] Operator '+' cannot be called on 'int?' because it is potentially null.
|
|
(nonNullInt ?? nonNullInt) + 1;
|
|
// ^
|
|
// [cfe] Operand of null-aware operation '??' has type 'int' which excludes null.
|
|
// ^^^^^^^^^^
|
|
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
|
|
}
|
|
|
|
// TODO(mfairhurst) add cases with type parameter types
|