Files
sdk/pkg/front_end/testcases/nnbd/later.dart
T
Johnni Winther c7da96dade [cfe] Report error on await in late local initializer
Closes #40090

Change-Id: I2b3864fa2b77da021b6cc73b79ac91121ee4fec1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131621
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-01-14 14:04:25 +00:00

58 lines
1.1 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.
// This test checks for compile-time errors and their absence for some use cases
// of late fields and variables.
class A {
int a = 42;
late int b = (this.a * 2) >> 1; // Ok.
foo(late int x) {}
}
bar(late int x) {}
baz() {
try {
throw "baz";
} on dynamic catch (late e, late t) {}
for (late int i = 0; i < 10; ++i) {
print("baz");
}
for (late String s in ["baz"]) {
print(s);
}
[for (late int i = 0; i < 10; ++i) i];
}
hest() async {
await for (late String s in new Stream.fromIterable(["hest"])) {
print(s);
}
return "hest";
}
fisk() async {
late String s1 = await hest();
late String s2 = '${fisk}${await hest()}${fisk}';
late Function f = () async => await hest();
}
class B {
late final int x = 42;
const B();
}
class C {
late final int x;
initVars() {
x = 42; // Ok: [x] doesn't have an initializer.
}
}
main() {}