Files
sdk/tests/language/nnbd/syntax/non_null_assertion_test.dart
T
Lasse R.H. Nielsen d352bc28b8 Remove (most) uses of the "non-nullable" experiment flag.
Since the flag is now enabled by default, there should be no mention of it.
There are still some uses in front_end/testcases that are not just removable
(it also uses `no-non-nullable`). There migth be more uses that are not
as easily found as grepping for `--enable-experiment

Removes two VM tests where fixing them meant they were just duplicating
the corresponding non *_2/ tests.
Fixes #44941

TEST= Large number of tests chaged.=(no-)?non-nullable`.

Change-Id: Ief755981ccde9a5482fcdf408c2929c74433a710
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183688
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2021-02-12 17:16:54 +00:00

75 lines
1.9 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 the trailing "!" is accepted after a sampling of expression
// syntaxes. Verify that the compiler understands the resulting type to be
// non-nullable by constructing a list containing the expression, and assigning
// it to List<Object>. Where possible, verify that the runtime implements the
// proper null-check semantics by verifying that the presence of `null` causes
// an exception to be thrown.
import 'package:expect/expect.dart';
class C {
const C();
Object? get x => null;
void f() {}
}
Object? f() => null;
main() {
List<Object> listOfObject = [];
var x1 = [0!]; // ignore: unnecessary_non_null_assertion
listOfObject = x1;
var x2 = [true!]; // ignore: unnecessary_non_null_assertion
listOfObject = x2;
var x3 = ["foo"!]; // ignore: unnecessary_non_null_assertion
listOfObject = x3;
var x4 = [#foo!]; // ignore: unnecessary_non_null_assertion
listOfObject = x4;
var x5 = [[1]!]; // ignore: unnecessary_non_null_assertion
listOfObject = x5;
var x6 = [{1:2}!]; // ignore: unnecessary_non_null_assertion
listOfObject = x6;
var x7 = [{1}!]; // ignore: unnecessary_non_null_assertion
listOfObject = x7;
var x8 = [new C()!]; // ignore: unnecessary_non_null_assertion
listOfObject = x8;
var x9 = [const C()!]; // ignore: unnecessary_non_null_assertion
listOfObject = x9;
Expect.throws(() {
var x10 = [f()!];
listOfObject = x10;
});
C c = new C();
Expect.throws(() {
var x11 = [c.x!];
listOfObject = x11;
});
var g = f;
Expect.throws(() {
var x12 = [g()!];
listOfObject = x12;
});
int i = 0;
var x13 = [(i++)!]; // ignore: unnecessary_non_null_assertion
listOfObject = x13;
}