Files
sdk/pkg/front_end/testcases/nnbd/strictly_non_nullable_warnings.dart
T
Dmitry Stefantsov 11790fe024 [cfe] Warn about non-nullable operands in null-aware operations
Closes #40094.

Bug: http://dartbug.com/40094
Change-Id: I3af5258bf0845257915eb090889fde0fdcb96bf9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134339
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-02-06 11:06:41 +00:00

50 lines
1.4 KiB
Dart

// 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.
// The test checks for compile-time warnings about expressions of strictly
// non-nullable types being used in positions typically occupied by those of
// nullable types, that is, in various null-aware expressions.
extension E on String {
int get foo => 42;
void operator[]=(int index, int value) {}
int operator[](int index) => 42;
}
class A {
String operator[](int index) => "foo";
void operator[]=(int index, String value) {}
}
class B extends A {
void test() {
super[42] ??= "bar"; // Warning.
}
}
warning(String s, List<String> l, Map<String, int> m) {
s?.length; // Warning.
s?..length; // Warning.
s ?? "foo"; // Warning.
s ??= "foo"; // Warning.
[...?l]; // Warning.
var a = {...?l}; // Warning.
<String>{...?l}; // Warning.
var b = {...?m}; // Warning.
<String, int>{...?m}; // Warning.
s!; // Warning.
s?.substring(0, 0); // Warning.
l?.length = 42; // Warning.
l?.length += 42; // Warning.
l?.length ??= 42; // Warning.
s?.foo; // Warning.
E(s)[42] ??= 42; // Warning.
l[42] ??= "foo"; // Warning.
l.length ??= 42; // Warning.
l?..length = 42; // Warning.
l?..length ??= 42; // Warning.
}
main() {}