Files
sdk/tests/language/nnbd/syntax/late_modifier_local_var_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

72 lines
2.0 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.
// VMOptions=--optimization_counter_threshold=10
import 'package:expect/expect.dart';
int initCalls = 0;
int init() {
++initCalls;
return 123;
}
main() {
for (int i = 0; i < 20; ++i) {
late int varWithInit = init();
late int varWithTrivialInit = 123;
late int? varWithNullInit = null;
late int varWithNoInit;
Expect.equals(0, initCalls);
Expect.equals(123, varWithInit);
Expect.equals(123, varWithTrivialInit);
Expect.equals(null, varWithNullInit);
Expect.throws<Error>(() => varWithNoInit);
Expect.equals(1, initCalls);
Expect.equals(123, varWithInit);
Expect.equals(123, varWithTrivialInit);
Expect.equals(null, varWithNullInit);
Expect.throws<Error>(() => varWithNoInit);
Expect.equals(1, initCalls);
varWithInit = 456;
varWithTrivialInit = 456;
varWithNullInit = 456;
varWithNoInit = 456;
Expect.equals(1, initCalls);
Expect.equals(456, varWithInit);
Expect.equals(456, varWithTrivialInit);
Expect.equals(456, varWithNullInit);
Expect.equals(456, varWithNoInit);
Expect.equals(1, initCalls);
initCalls = 0;
late int varWithInit2 = init();
Expect.equals(0, initCalls);
varWithInit2 = 456;
Expect.equals(0, initCalls);
Expect.equals(456, varWithInit2);
Expect.equals(0, initCalls);
late int? varWithInit3 = init();
Expect.equals(0, initCalls);
varWithInit3 = null;
Expect.equals(0, initCalls);
Expect.equals(null, varWithInit3);
Expect.equals(0, initCalls);
late int varWithCondInit = null ?? init();
var lambda = () {
Expect.equals(123, varWithCondInit);
Expect.equals(1, initCalls);
};
lambda();
lambda();
lambda();
initCalls = 0;
if (true) late int varNotInBlock = init();
Expect.equals(0, initCalls);
initCalls = 0;
}
}