#459. Late fields and variables tests added
diff --git a/LanguageFeatures/nnbd/late_A01_t01.dart b/LanguageFeatures/nnbd/late_A01_t01.dart
new file mode 100644
index 0000000..971c6a5
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A01_t01.dart
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A read of a field or variable which is marked as late which has
+ * not yet been written to causes the initializer expression of the variable to
+ * be evaluated to a value, assigned to the variable or field, and returned as
+ * the value of the read.
+ *
+ * @description Check that a read of a field or variable which is marked as late
+ * which has not yet been written to causes the initializer expression of the
+ * variable to be evaluated to a value, assigned to the variable or field, and
+ * returned as the value of the read
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+
+String _log = "";
+
+String init(String val) {
+ _log += "init('$val')";
+ return val;
+}
+
+void clearLog() {
+ _log = "";
+}
+
+class C {
+ static late final String s1 = init("When");
+ static late String s2 = init("I found");
+ covariant late String v1 = init("myself");
+ late final String v2 = init("in time");
+ late String v3 = init("of trouble");
+}
+
+late final String g1 = init("Mother Mary");
+late String g2 = init("comes to me");
+
+main() {
+ late final String l1 = init("Speaking words of wisdom");
+ late String l2 = init("let it be");
+
+ Expect.equals("", _log);
+ Expect.equals("When", C.s1);
+ Expect.equals("init('When')", _log);
+ clearLog();
+
+ Expect.equals("I found", C.s2);
+ Expect.equals("init('I found')", _log);
+ clearLog();
+
+ C c = new C();
+ Expect.equals("", _log);
+ Expect.equals("myself", c.v1);
+ Expect.equals("init('myself')", _log);
+ clearLog();
+
+ Expect.equals("in time", c.v2);
+ Expect.equals("init('in time')", _log);
+ clearLog();
+
+ Expect.equals("of trouble", c.v3);
+ Expect.equals("init('of trouble')", _log);
+ clearLog();
+
+ Expect.equals("Mother Mary", g1);
+ Expect.equals("init('Mother Mary')", _log);
+ clearLog();
+
+ Expect.equals("comes to me", g2);
+ Expect.equals("init('comes to me')", _log);
+ clearLog();
+
+ Expect.equals("Speaking words of wisdom", l1);
+ Expect.equals("init('Speaking words of wisdom')", _log);
+ clearLog();
+
+ Expect.equals("let it be", l2);
+ Expect.equals("init('let it be')", _log);
+ clearLog();
+}
diff --git a/LanguageFeatures/nnbd/late_A01_t02.dart b/LanguageFeatures/nnbd/late_A01_t02.dart
new file mode 100644
index 0000000..5ddb863
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A01_t02.dart
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A read of a field or variable which is marked as late which has
+ * not yet been written to causes the initializer expression of the variable to
+ * be evaluated to a value, assigned to the variable or field, and returned as
+ * the value of the read.
+ *
+ * @description Check that a read of a field or variable which is marked as late
+ * which has not yet been written to causes the initializer expression of the
+ * variable to be evaluated to a value, assigned to the variable or field, and
+ * returned as the value of the read
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+
+String _log = "";
+
+String init(String val) {
+ _log += "init('$val')";
+ return val;
+}
+
+void clearLog() {
+ _log = "";
+}
+
+class C {
+ static late final String? s1 = init("When");
+ static late String? s2 = init("I found");
+ covariant late String? v1 = init("myself");
+ late final String? v2 = init("in time");
+ late String? v3 = init("of trouble");
+}
+
+late final String? g1 = init("Mother Mary");
+late String? g2 = init("comes to me");
+
+main() {
+ late final String? l1 = init("Speaking words of wisdom");
+ late String? l2 = init("let it be");
+
+ Expect.equals("", _log);
+ Expect.equals("When", C.s1);
+ Expect.equals("init('When')", _log);
+ clearLog();
+
+ Expect.equals("I found", C.s2);
+ Expect.equals("init('I found')", _log);
+ clearLog();
+
+ C c = new C();
+ Expect.equals("", _log);
+ Expect.equals("myself", c.v1);
+ Expect.equals("init('myself')", _log);
+ clearLog();
+
+ Expect.equals("in time", c.v2);
+ Expect.equals("init('in time')", _log);
+ clearLog();
+
+ Expect.equals("of trouble", c.v3);
+ Expect.equals("init('of trouble')", _log);
+ clearLog();
+
+ Expect.equals("Mother Mary", g1);
+ Expect.equals("init('Mother Mary')", _log);
+ clearLog();
+
+ Expect.equals("comes to me", g2);
+ Expect.equals("init('comes to me')", _log);
+ clearLog();
+
+ Expect.equals("Speaking words of wisdom", l1);
+ Expect.equals("init('Speaking words of wisdom')", _log);
+ clearLog();
+
+ Expect.equals("let it be", l2);
+ Expect.equals("init('let it be')", _log);
+ clearLog();
+}
diff --git a/LanguageFeatures/nnbd/late_A02_t01.dart b/LanguageFeatures/nnbd/late_A02_t01.dart
new file mode 100644
index 0000000..a9e5810
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A02_t01.dart
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A read of a field or variable which is marked as late which has
+ * not yet been written to causes the initializer expression of the variable to
+ * be evaluated to a value, assigned to the variable or field, and returned as
+ * the value of the read.
+ *
+ * If there is no initializer expression, the read causes a runtime error.
+ *
+ * @description Check that it is a runtime error to read late variable without
+ * initializer expression
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+
+class C {
+ static late final String s1;
+ static late String s2;
+ covariant late String v1;
+ late final String v2;
+ late String v3;
+}
+
+late final String g1;
+late String g2;
+
+main() {
+ late final String l1;
+ late String l2;
+
+ Expect.throws(() {C.s1;});
+ Expect.throws(() {C.s2;});
+ C c = new C();
+ Expect.throws(() {c.v1;});
+ Expect.throws(() {c.v2;});
+ Expect.throws(() {c.v3;});
+
+ Expect.throws(() {g1;});
+ Expect.throws(() {g2;});
+ Expect.throws(() {l1;});
+ Expect.throws(() {l2;});
+}
diff --git a/LanguageFeatures/nnbd/late_A02_t02.dart b/LanguageFeatures/nnbd/late_A02_t02.dart
new file mode 100644
index 0000000..3caa78e
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A02_t02.dart
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A read of a field or variable which is marked as late which has
+ * not yet been written to causes the initializer expression of the variable to
+ * be evaluated to a value, assigned to the variable or field, and returned as
+ * the value of the read.
+ *
+ * If there is no initializer expression, the read causes a runtime error.
+ *
+ * @description Check that it is a runtime error to read late variable without
+ * initializer expression
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+
+class C {
+ static late final String? s1;
+ static late String? s2;
+ covariant late String? v1;
+ late final String? v2;
+ late String? v3;
+}
+
+late final String? g1;
+late String? g2;
+
+main() {
+ late final String? l1;
+ late String? l2;
+
+ Expect.throws(() {C.s1;});
+ Expect.throws(() {C.s2;});
+ C c = new C();
+ Expect.throws(() {c.v1;});
+ Expect.throws(() {c.v2;});
+ Expect.throws(() {c.v3;});
+
+ Expect.throws(() {g1;});
+ Expect.throws(() {g2;});
+ Expect.throws(() {l1;});
+ Expect.throws(() {l2;});
+}
diff --git a/LanguageFeatures/nnbd/late_A03_t01.dart b/LanguageFeatures/nnbd/late_A03_t01.dart
new file mode 100644
index 0000000..2e5b4be
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A03_t01.dart
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A read of a field or variable which is marked as late which has
+ * not yet been written to causes the initializer expression of the variable to
+ * be evaluated to a value, assigned to the variable or field, and returned as
+ * the value of the read.
+ * ...
+ * Evaluating the initializer expression may validly cause a write to the field
+ * or variable, assuming that the field or variable is not final. In this case,
+ * the variable assumes the written value. The final value of the initializer
+ * expression overwrites any intermediate written values.
+ *
+ * @description Check that evaluating the initializer expression may validly
+ * cause a write to the field or variable, assuming that the field or variable
+ * is not final. In this case, the variable assumes the written value. The final
+ * value of the initializer expression overwrites any intermediate written
+ * values.
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+
+class C {
+ static String initS(String val1, String val2) {
+ s = val1;
+ return val2;
+ }
+ static late String s = initS("No woman", "no cry");
+
+ covariant late String v1 = initV1("No woman", "no cry");
+ late String v2 = initV2("No woman", "no cry");
+
+ initV1(String val1, String val2) {
+ v1 = val1;
+ return val2;
+ }
+
+ initV2(String val1, String val2) {
+ v2 = val1;
+ return val2;
+ }
+}
+
+late String g = initG("No woman", "no cry");
+
+initG(String val1, String val2) {
+ g = val1;
+ return val2;
+}
+
+main() {
+ late String l = initL("No woman", "no cry");
+
+ initL(String val1, String val2) {
+ l = val1;
+ return val2;
+ }
+ Expect.equals("no cry", C.s);
+ Expect.equals("no cry", g);
+ Expect.equals("no cry", l);
+ C c = new C();
+ Expect.equals("no cry", c.v1);
+ Expect.equals("no cry", c.v2);
+}
diff --git a/LanguageFeatures/nnbd/late_A03_t02.dart b/LanguageFeatures/nnbd/late_A03_t02.dart
new file mode 100644
index 0000000..663bff0
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A03_t02.dart
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A read of a field or variable which is marked as late which has
+ * not yet been written to causes the initializer expression of the variable to
+ * be evaluated to a value, assigned to the variable or field, and returned as
+ * the value of the read.
+ * ...
+ * Evaluating the initializer expression may validly cause a write to the field
+ * or variable, assuming that the field or variable is not final. In this case,
+ * the variable assumes the written value. The final value of the initializer
+ * expression overwrites any intermediate written values.
+ *
+ * @description Check that evaluating the initializer expression may validly
+ * cause a write to the field or variable, assuming that the field or variable
+ * is not final. In this case, the variable assumes the written value. The final
+ * value of the initializer expression overwrites any intermediate written
+ * values.
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+
+class C {
+ static String initS(String val1, String val2) {
+ s = val1;
+ return val2;
+ }
+ static late String? s = initS("No woman", "no cry");
+
+ covariant late String? v1 = initV1("No woman", "no cry");
+ late String? v2 = initV2("No woman", "no cry");
+
+ initV1(String val1, String val2) {
+ v1 = val1;
+ return val2;
+ }
+
+ initV2(String val1, String val2) {
+ v2 = val1;
+ return val2;
+ }
+}
+
+late String? g = initG("No woman", "no cry");
+
+initG(String val1, String val2) {
+ g = val1;
+ return val2;
+}
+
+main() {
+ late String? l = initL("No woman", "no cry");
+
+ initL(String val1, String val2) {
+ l = val1;
+ return val2;
+ }
+ Expect.equals("no cry", C.s);
+ Expect.equals("no cry", g);
+ Expect.equals("no cry", l);
+ C c = new C();
+ Expect.equals("no cry", c.v1);
+ Expect.equals("no cry", c.v2);
+}
diff --git a/LanguageFeatures/nnbd/late_A03_t03.dart b/LanguageFeatures/nnbd/late_A03_t03.dart
new file mode 100644
index 0000000..2be1685
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A03_t03.dart
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A read of a field or variable which is marked as late which has
+ * not yet been written to causes the initializer expression of the variable to
+ * be evaluated to a value, assigned to the variable or field, and returned as
+ * the value of the read.
+ * ...
+ * Evaluating the initializer expression may validly cause a write to the field
+ * or variable, assuming that the field or variable is not final. In this case,
+ * the variable assumes the written value. The final value of the initializer
+ * expression overwrites any intermediate written values.
+ *
+ * @description Check that it is a compile error if initializing expression
+ * writes an intermediate value to final field or variable
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+
+class C {
+ static String initS(String val1, String val2) {
+ s = val1;
+// ^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ return val2;
+ }
+ static late final String s = initS("No woman", "no cry");
+
+ late final String v = initV("No woman", "no cry");
+
+ initV(String val1, String val2) {
+ v = val1;
+// ^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ return val2;
+ }
+}
+
+late final String g = initG("No woman", "no cry");
+
+initG(String val1, String val2) {
+ g = val1;
+// ^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ return val2;
+}
+
+main() {
+ late final String l = initL("No woman", "no cry");
+
+ initL(String val1, String val2) {
+ l = val1;
+// ^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ return val2;
+ }
+}
diff --git a/LanguageFeatures/nnbd/late_A04_t01.dart b/LanguageFeatures/nnbd/late_A04_t01.dart
new file mode 100644
index 0000000..84c9c92
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A04_t01.dart
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A read of a field or variable which is marked as late which has
+ * not yet been written to causes the initializer expression of the variable to
+ * be evaluated to a value, assigned to the variable or field, and returned as
+ * the value of the read.
+ * ...
+ * Evaluating the initializer expression may cause an exception to be thrown. If
+ * the variable was written to before the exception was thrown, the value of the
+ * variable on subsequent reads is the last written value. If the variable was
+ * not written before the exception was thrown, then the next read attempts to
+ * evaluate the initializer expression again.
+ *
+ * @description Check that if evaluating of the initializer expression throws an
+ * exception then the value of the variable is the last written value
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+
+class C {
+ static String initS(String val1, String val2) {
+ s = val1;
+ throw new Exception();
+ }
+ static late String s = initS("No woman", "no cry");
+
+ covariant late String v1 = initV1("No woman", "no cry");
+ late String v2 = initV2("No woman", "no cry");
+
+ initV1(String val1, String val2) {
+ v1 = val1;
+ throw new Exception();
+ }
+
+ initV2(String val1, String val2) {
+ v2 = val1;
+ throw new Exception();
+ }
+}
+
+late String g = initG("No woman", "no cry");
+
+initG(String val1, String val2) {
+ g = val1;
+ throw new Exception();
+}
+
+main() {
+ late String l = initL("No woman", "no cry");
+
+ initL(String val1, String val2) {
+ l = val1;
+ throw new Exception();
+ }
+ Expect.throws(() {C.s;});
+ Expect.equals("No woman", C.s);
+ Expect.throws(() {g;});
+ Expect.equals("No woman", g);
+ Expect.throws(() {l;});
+ Expect.equals("No woman", l);
+ C c = new C();
+ Expect.throws(() {c.v1;});
+ Expect.equals("No woman", c.v1);
+ Expect.throws(() {c.v2;});
+ Expect.equals("No woman", c.v2);
+}
diff --git a/LanguageFeatures/nnbd/late_A04_t02.dart b/LanguageFeatures/nnbd/late_A04_t02.dart
new file mode 100644
index 0000000..ec98a96
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A04_t02.dart
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A read of a field or variable which is marked as late which has
+ * not yet been written to causes the initializer expression of the variable to
+ * be evaluated to a value, assigned to the variable or field, and returned as
+ * the value of the read.
+ * ...
+ * Evaluating the initializer expression may cause an exception to be thrown. If
+ * the variable was written to before the exception was thrown, the value of the
+ * variable on subsequent reads is the last written value. If the variable was
+ * not written before the exception was thrown, then the next read attempts to
+ * evaluate the initializer expression again.
+ *
+ * @description Check that if evaluating of the initializer expression throws an
+ * exception then the value of the variable is the last written value
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+
+class C {
+ static String initS(String val1, String val2) {
+ s = val1;
+ throw new Exception();
+ }
+ static late String? s = initS("No woman", "no cry");
+
+ covariant late String? v1 = initV1("No woman", "no cry");
+ late String? v2 = initV2("No woman", "no cry");
+
+ initV1(String val1, String val2) {
+ v1 = val1;
+ throw new Exception();
+ }
+
+ initV2(String val1, String val2) {
+ v2 = val1;
+ throw new Exception();
+ }
+}
+
+late String? g = initG("No woman", "no cry");
+
+initG(String val1, String val2) {
+ g = val1;
+ throw new Exception();
+}
+
+main() {
+ late String? l = initL("No woman", "no cry");
+
+ initL(String val1, String val2) {
+ l = val1;
+ throw new Exception();
+ }
+ Expect.throws(() {C.s;});
+ Expect.equals("No woman", C.s);
+ Expect.throws(() {g;});
+ Expect.equals("No woman", g);
+ Expect.throws(() {l;});
+ Expect.equals("No woman", l);
+ C c = new C();
+ Expect.throws(() {c.v1;});
+ Expect.equals("No woman", c.v1);
+ Expect.throws(() {c.v2;});
+ Expect.equals("No woman", c.v2);
+}
diff --git a/LanguageFeatures/nnbd/late_A04_t03.dart b/LanguageFeatures/nnbd/late_A04_t03.dart
new file mode 100644
index 0000000..6987e9d
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A04_t03.dart
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A read of a field or variable which is marked as late which has
+ * not yet been written to causes the initializer expression of the variable to
+ * be evaluated to a value, assigned to the variable or field, and returned as
+ * the value of the read.
+ * ...
+ * Evaluating the initializer expression may cause an exception to be thrown. If
+ * the variable was written to before the exception was thrown, the value of the
+ * variable on subsequent reads is the last written value. If the variable was
+ * not written before the exception was thrown, then the next read attempts to
+ * evaluate the initializer expression again.
+ *
+ * @description Check that if evaluating of the initializer expression throws an
+ * exception and the value of the variable was not written to then next read
+ * attempts to evaluate the initializer expression again
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+
+String _log = "";
+bool _called = false;
+
+String init(String val) {
+ _log += "init('$val')";
+ if (!_called) {
+ _called = true;
+ throw new Exception();
+ }
+ return val;
+}
+
+void clearLog() {
+ _log = "";
+ _called = false;
+}
+
+class C {
+ static late String s = init("Lily");
+ covariant late String v1 = init("was");
+ late String v2 = init("here");
+}
+
+late String g = init("Let it be");
+
+main() {
+ late String l = init("Run, Forrest, run");
+
+ Expect.equals("", _log);
+ Expect.throws(() {C.s;});
+ Expect.equals("Lily", C.s);
+ Expect.equals("init('Lily')init('Lily')", _log);
+ clearLog();
+
+ C c = new C();
+ Expect.equals("", _log);
+ Expect.throws(() {c.v1;});
+ Expect.equals("was", c.v1);
+ Expect.equals("init('was')init('was')", _log);
+ clearLog();
+
+ Expect.throws(() {g;});
+ Expect.equals("Let it be", g);
+ Expect.equals("init('Let it be')init('Let it be')", _log);
+ clearLog();
+
+ Expect.throws(() {l;});
+ Expect.equals("Run, Forrest, run", l);
+ Expect.equals("init('Run, Forrest, run')init('Run, Forrest, run')", _log);
+ clearLog();
+}
diff --git a/LanguageFeatures/nnbd/late_A04_t04.dart b/LanguageFeatures/nnbd/late_A04_t04.dart
new file mode 100644
index 0000000..7fa8274
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A04_t04.dart
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+/**
+ * @assertion A read of a field or variable which is marked as late which has
+ * not yet been written to causes the initializer expression of the variable to
+ * be evaluated to a value, assigned to the variable or field, and returned as
+ * the value of the read.
+ * ...
+ * Evaluating the initializer expression may cause an exception to be thrown. If
+ * the variable was written to before the exception was thrown, the value of the
+ * variable on subsequent reads is the last written value. If the variable was
+ * not written before the exception was thrown, then the next read attempts to
+ * evaluate the initializer expression again.
+ *
+ * @description Check that if evaluating of the initializer expression throws an
+ * exception and the value of the variable was not written to then next read
+ * attempts to evaluate the initializer expression again
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+
+String _log = "";
+bool _called = false;
+
+String init(String val) {
+ _log += "init('$val')";
+ if (!_called) {
+ _called = true;
+ throw new Exception();
+ }
+ return val;
+}
+
+void clearLog() {
+ _log = "";
+ _called = false;
+}
+
+class C {
+ static late String? s = init("Lily");
+ covariant late String? v1 = init("was");
+ late String? v2 = init("here");
+}
+
+late String? g = init("Let it be");
+
+main() {
+ late String? l = init("Run, Forrest, run");
+
+ Expect.equals("", _log);
+ Expect.throws(() {C.s;});
+ Expect.equals("Lily", C.s);
+ Expect.equals("init('Lily')init('Lily')", _log);
+ clearLog();
+
+ C c = new C();
+ Expect.equals("", _log);
+ Expect.throws(() {c.v1;});
+ Expect.equals("was", c.v1);
+ Expect.equals("init('was')init('was')", _log);
+ clearLog();
+
+ Expect.throws(() {g;});
+ Expect.equals("Let it be", g);
+ Expect.equals("init('Let it be')init('Let it be')", _log);
+ clearLog();
+
+ Expect.throws(() {l;});
+ Expect.equals("Run, Forrest, run", l);
+ Expect.equals("init('Run, Forrest, run')init('Run, Forrest, run')", _log);
+ clearLog();
+}