Late variables tests fixed and new ones added
diff --git a/LanguageFeatures/nnbd/late_A01_t01.dart b/LanguageFeatures/nnbd/late_A01_t01.dart
index 971c6a5..c53b0ab 100644
--- a/LanguageFeatures/nnbd/late_A01_t01.dart
+++ b/LanguageFeatures/nnbd/late_A01_t01.dart
@@ -44,7 +44,9 @@
late final String l1 = init("Speaking words of wisdom");
late String l2 = init("let it be");
- Expect.equals("", _log);
+ Expect.equals("init('Speaking words of wisdom')init('let it be')", _log);
+ clearLog();
+
Expect.equals("When", C.s1);
Expect.equals("init('When')", _log);
clearLog();
@@ -76,10 +78,9 @@
clearLog();
Expect.equals("Speaking words of wisdom", l1);
- Expect.equals("init('Speaking words of wisdom')", _log);
+ Expect.equals("", _log);
clearLog();
Expect.equals("let it be", l2);
- Expect.equals("init('let it be')", _log);
- clearLog();
+ Expect.equals("", _log);
}
diff --git a/LanguageFeatures/nnbd/late_A01_t02.dart b/LanguageFeatures/nnbd/late_A01_t02.dart
index 5ddb863..ca93446 100644
--- a/LanguageFeatures/nnbd/late_A01_t02.dart
+++ b/LanguageFeatures/nnbd/late_A01_t02.dart
@@ -44,6 +44,9 @@
late final String? l1 = init("Speaking words of wisdom");
late String? l2 = init("let it be");
+ Expect.equals("init('Speaking words of wisdom')init('let it be')", _log);
+ clearLog();
+
Expect.equals("", _log);
Expect.equals("When", C.s1);
Expect.equals("init('When')", _log);
@@ -76,10 +79,9 @@
clearLog();
Expect.equals("Speaking words of wisdom", l1);
- Expect.equals("init('Speaking words of wisdom')", _log);
+ Expect.equals("", _log);
clearLog();
Expect.equals("let it be", l2);
- Expect.equals("init('let it be')", _log);
- clearLog();
+ Expect.equals("", _log);
}
diff --git a/LanguageFeatures/nnbd/late_A02_t01.dart b/LanguageFeatures/nnbd/late_A02_t01.dart
index a9e5810..f2e18c2 100644
--- a/LanguageFeatures/nnbd/late_A02_t01.dart
+++ b/LanguageFeatures/nnbd/late_A02_t01.dart
@@ -9,11 +9,13 @@
* 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.
+ * If there is no initializer expression, the read causes a runtime error to be
+ * thrown which is an instance of LateInitializationError
*
* @description Check that it is a runtime error to read late variable without
* initializer expression
* @author sgrekhov@unipro.ru
+ * @issue 39801
*/
// SharedOptions=--enable-experiment=non-nullable
import "../../Utils/expect.dart";
@@ -33,15 +35,15 @@
late final String l1;
late String l2;
- Expect.throws(() {C.s1;});
- Expect.throws(() {C.s2;});
+ Expect.throws(() {C.s1;}, (e) => e is LateInitializationError);
+ Expect.throws(() {C.s2;}, (e) => e is LateInitializationError);
C c = new C();
- Expect.throws(() {c.v1;});
- Expect.throws(() {c.v2;});
- Expect.throws(() {c.v3;});
+ Expect.throws(() {c.v1;}, (e) => e is LateInitializationError);
+ Expect.throws(() {c.v2;}, (e) => e is LateInitializationError);
+ Expect.throws(() {c.v3;}, (e) => e is LateInitializationError);
- Expect.throws(() {g1;});
- Expect.throws(() {g2;});
- Expect.throws(() {l1;});
- Expect.throws(() {l2;});
+ Expect.throws(() {g1;}, (e) => e is LateInitializationError);
+ Expect.throws(() {g2;}, (e) => e is LateInitializationError);
+ Expect.throws(() {l1;}, (e) => e is LateInitializationError);
+ Expect.throws(() {l2;}, (e) => e is LateInitializationError);
}
diff --git a/LanguageFeatures/nnbd/late_A02_t02.dart b/LanguageFeatures/nnbd/late_A02_t02.dart
index 3caa78e..9afad67 100644
--- a/LanguageFeatures/nnbd/late_A02_t02.dart
+++ b/LanguageFeatures/nnbd/late_A02_t02.dart
@@ -9,11 +9,13 @@
* 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.
+ * If there is no initializer expression, the read causes a runtime error to be
+ * thrown which is an instance of LateInitializationError
*
* @description Check that it is a runtime error to read late variable without
* initializer expression
* @author sgrekhov@unipro.ru
+ * @issue 39801
*/
// SharedOptions=--enable-experiment=non-nullable
import "../../Utils/expect.dart";
@@ -33,15 +35,15 @@
late final String? l1;
late String? l2;
- Expect.throws(() {C.s1;});
- Expect.throws(() {C.s2;});
+ Expect.throws(() {C.s1;}, (e) => e is LateInitializationError);
+ Expect.throws(() {C.s2;}, (e) => e is LateInitializationError);
C c = new C();
- Expect.throws(() {c.v1;});
- Expect.throws(() {c.v2;});
- Expect.throws(() {c.v3;});
+ Expect.throws(() {c.v1;}, (e) => e is LateInitializationError);
+ Expect.throws(() {c.v2;}, (e) => e is LateInitializationError);
+ Expect.throws(() {c.v3;}, (e) => e is LateInitializationError);
- Expect.throws(() {g1;});
- Expect.throws(() {g2;});
- Expect.throws(() {l1;});
- Expect.throws(() {l2;});
+ Expect.throws(() {g1;}, (e) => e is LateInitializationError);
+ Expect.throws(() {g2;}, (e) => e is LateInitializationError);
+ Expect.throws(() {l1;}, (e) => e is LateInitializationError);
+ Expect.throws(() {l2;}, (e) => e is LateInitializationError);
}
diff --git a/LanguageFeatures/nnbd/late_A02_t03.dart b/LanguageFeatures/nnbd/late_A02_t03.dart
deleted file mode 100644
index a3a18ff..0000000
--- a/LanguageFeatures/nnbd/late_A02_t03.dart
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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 A1 {
- covariant late String v;
- A1() : this.v = (this.v == "" ? "one": "two");
-}
-
-class A2 {
- covariant late String? v;
- A2() : this.v = (this.v == "" ? "one": "two");
-}
-
-class B1 {
- late final String v;
- B1() : this.v = (this.v == "" ? "one": "two");
-}
-
-class B2 {
- late final String v;
- B2() : this.v = (this.v == "" ? "one": "two");
-}
-
-class C1 {
- late String v;
- C1() : this.v = (this.v == "" ? "one": "two");
-}
-
-class C2 {
- late String v;
- C2() : this.v = (this.v == "" ? "one": "two");
-}
-
-main() {
- Expect.throws(() {new A1();});
- Expect.throws(() {new B1();});
- Expect.throws(() {new C1();});
- Expect.throws(() {new A2();});
- Expect.throws(() {new B2();});
- Expect.throws(() {new C2();});
-}
diff --git a/LanguageFeatures/nnbd/late_A03_t01.dart b/LanguageFeatures/nnbd/late_A03_t01.dart
index 2e5b4be..3a8bbaa 100644
--- a/LanguageFeatures/nnbd/late_A03_t01.dart
+++ b/LanguageFeatures/nnbd/late_A03_t01.dart
@@ -53,15 +53,8 @@
}
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
index 663bff0..5772442 100644
--- a/LanguageFeatures/nnbd/late_A03_t02.dart
+++ b/LanguageFeatures/nnbd/late_A03_t02.dart
@@ -53,15 +53,8 @@
}
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
index 2be1685..543b868 100644
--- a/LanguageFeatures/nnbd/late_A03_t03.dart
+++ b/LanguageFeatures/nnbd/late_A03_t03.dart
@@ -14,55 +14,46 @@
* 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
+ * @description Check that it is a runtime error if initializing expression
* writes an intermediate value to final field or variable
* @author sgrekhov@unipro.ru
+ * @issue 39802
*/
// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
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;
- }
+ static late final String s;
+ late final String v;
}
-late final String g = initG("No woman", "no cry");
-
-initG(String val1, String val2) {
- g = val1;
-// ^^^^^^
-// [analyzer] unspecified
-// [cfe] unspecified
-
- return val2;
-}
+late final String g;
main() {
- late final String l = initL("No woman", "no cry");
+ late final String l;
- initL(String val1, String val2) {
- l = val1;
-// ^^^^^^
-// [analyzer] unspecified
-// [cfe] unspecified
+ C.s = "Lily was here";
+ Expect.equals("Lily was here", C.s);
+ Expect.throws(() {C.s = "Show must go on";},
+ (e) => e is LateInitializationError);
+ Expect.equals("Lily was here", C.s);
- return val2;
- }
+ C c = new C();
+ c.v = "Lily was here";
+ Expect.equals("Lily was here", c.v);
+ Expect.throws(() {c.v = "Show must go on";},
+ (e) => e is LateInitializationError);
+ Expect.equals("Lily was here", c.v);
+
+ g = "Lily was here";
+ Expect.equals("Lily was here", g);
+ Expect.throws(() {g = "Show must go on";},
+ (e) => e is LateInitializationError);
+ Expect.equals("Lily was here", g);
+
+ l = "Lily was here";
+ Expect.equals("Lily was here", l);
+ Expect.throws(() {l = "Show must go on";},
+ (e) => e is LateInitializationError);
+ Expect.equals("Lily was here", l);
}
diff --git a/LanguageFeatures/nnbd/late_A03_t04.dart b/LanguageFeatures/nnbd/late_A03_t04.dart
index 5803d81..fa1283b 100644
--- a/LanguageFeatures/nnbd/late_A03_t04.dart
+++ b/LanguageFeatures/nnbd/late_A03_t04.dart
@@ -14,39 +14,45 @@
* 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.
+ * @description Check that it is a runtime error if initializing expression
+ * writes an intermediate value to final field or variable
* @author sgrekhov@unipro.ru
*/
// SharedOptions=--enable-experiment=non-nullable
import "../../Utils/expect.dart";
-class A1 {
- covariant late String v;
- A1() : this.v = ((this.v = "Lily") == "lily" ? "was": "here");
+class C {
+ static late final String s;
+ static void initS(String val) {
+ s = val;
+ Expect.throws(() {s = "Show must go on";},
+ (e) => e is LateInitializationError);
+ }
+
+ late final String v;
+ void initV(String val) {
+ v = val;
+ Expect.throws(() {v = "Show must go on";},
+ (e) => e is LateInitializationError);
+ }
}
-class A2 {
- covariant late String v;
- A2() : this.v = ((this.v = "Lily") == "lily" ? "was": "here");
-}
+late final String g;
-class C1 {
- late String v;
- C1() : this.v = ((this.v = "Lily") == "lily" ? "was": "here");
-}
-
-class C2 {
- late String v;
- C2() : this.v = ((this.v = "Lily") == "lily" ? "was": "here");
+void initG(String val) {
+ g = val;
+ Expect.throws(() {g = "Show must go on";},
+ (e) => e is LateInitializationError);
}
main() {
- Expect.equals("here", new A1().v);
- Expect.equals("here", new A2().v);
- Expect.equals("here", new C1().v);
- Expect.equals("here", new C2().v);
+ C.initS("Lily was here");
+ Expect.equals("Lily was here", C.s);
+
+ C c = new C();
+ c.initV("Lily was here");
+ Expect.equals("Lily was here", c.v);
+
+ initG("Lily was here");
+ Expect.equals("Lily was here", g);
}
diff --git a/LanguageFeatures/nnbd/late_A04_t03.dart b/LanguageFeatures/nnbd/late_A04_t03.dart
index 6987e9d..32ef503 100644
--- a/LanguageFeatures/nnbd/late_A04_t03.dart
+++ b/LanguageFeatures/nnbd/late_A04_t03.dart
@@ -49,8 +49,6 @@
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);
@@ -68,9 +66,4 @@
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
index 7fa8274..fbd6c7e 100644
--- a/LanguageFeatures/nnbd/late_A04_t04.dart
+++ b/LanguageFeatures/nnbd/late_A04_t04.dart
@@ -49,8 +49,6 @@
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);
@@ -68,9 +66,4 @@
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_t05.dart b/LanguageFeatures/nnbd/late_A04_t05.dart
deleted file mode 100644
index d87db63..0000000
--- a/LanguageFeatures/nnbd/late_A04_t05.dart
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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
- * @issue 38734
- */
-// SharedOptions=--enable-experiment=non-nullable
-import "../../Utils/expect.dart";
-
-class C {
- covariant late String v1;
- late String v2 = initV2("No woman", "no cry");
-
- C() : v1 = initV1("No woman", "no cry"), 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();
- }
-}
-
-main() {
- 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_t06.dart b/LanguageFeatures/nnbd/late_A04_t06.dart
deleted file mode 100644
index 4ebce0a..0000000
--- a/LanguageFeatures/nnbd/late_A04_t06.dart
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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 {
- covariant late String? v1;
- late String? v2 = initV2("No woman", "no cry");
-
- C() : v1 = initV1("No woman", "no cry"), 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();
- }
-}
-
-
-main() {
- 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_A05_t01.dart b/LanguageFeatures/nnbd/late_A05_t01.dart
index 4039d66..4501d14 100644
--- a/LanguageFeatures/nnbd/late_A05_t01.dart
+++ b/LanguageFeatures/nnbd/late_A05_t01.dart
@@ -36,6 +36,7 @@
}
void clear() {
+ _log = "";
_counter = 0;
}
@@ -51,9 +52,6 @@
late String g2 = init("comes to me", (){g2;});
main() {
- late final String l1 = init("Speaking words of wisdom", (){l1;);
- late String l2 = init("let it be", (){l2;});
-
Expect.equals("", _log);
Expect.throws(() {C.s1;});
Expect.equals("When", C.s1);
@@ -91,14 +89,4 @@
Expect.throws(() {g2;});
Expect.equals("comes to me", g2);
Expect.equals("init('comes to me'), counter: 2", _log);
- clear();
-
- Expect.throws(() {l1;});
- Expect.equals("Speaking words of wisdom", l1);
- Expect.equals("init('Speaking words of wisdom'), counter: 2", _log);
- clear();
-
- Expect.throws(() {l2;});
- Expect.equals("let it be", l2);
- Expect.equals("init('let it be'), counter: 2", _log);
}
diff --git a/LanguageFeatures/nnbd/late_A05_t02.dart b/LanguageFeatures/nnbd/late_A05_t02.dart
index 6429357..f3b5abd 100644
--- a/LanguageFeatures/nnbd/late_A05_t02.dart
+++ b/LanguageFeatures/nnbd/late_A05_t02.dart
@@ -36,6 +36,7 @@
}
void clear() {
+ _log = "";
_counter = 0;
}
@@ -51,9 +52,6 @@
late String? g2 = init("comes to me", (){g2;});
main() {
- late final String? l1 = init("Speaking words of wisdom", (){l1;);
- late String? l2 = init("let it be", (){l2;});
-
Expect.equals("", _log);
Expect.throws(() {C.s1;});
Expect.equals("When", C.s1);
@@ -91,14 +89,4 @@
Expect.throws(() {g2;});
Expect.equals("comes to me", g2);
Expect.equals("init('comes to me'), counter: 2", _log);
- clear();
-
- Expect.throws(() {l1;});
- Expect.equals("Speaking words of wisdom", l1);
- Expect.equals("init('Speaking words of wisdom'), counter: 2", _log);
- clear();
-
- Expect.throws(() {l2;});
- Expect.equals("let it be", l2);
- Expect.equals("init('let it be'), counter: 2", _log);
}
diff --git a/LanguageFeatures/nnbd/late_A05_t03.dart b/LanguageFeatures/nnbd/late_A05_t03.dart
index 7621654..1035149 100644
--- a/LanguageFeatures/nnbd/late_A05_t03.dart
+++ b/LanguageFeatures/nnbd/late_A05_t03.dart
@@ -35,68 +35,24 @@
}
void clear() {
+ _log = "";
_counter = 0;
}
class C {
- static late final String s1 =
- init("No woman", "no cry", (){C.s1 = "Lily was here"; C.s1;});
- static late String s2 =
- init("No woman", "no cry", (){C.s2 = "Lily was here"; C.s2;});
- covariant late String v1 =
- init("No woman", "no cry", (){this.v1 = "Lily was here"; this.v1;});
- late final String v2 =
- init("No woman", "no cry", (){this.v2 = "Lily was here"; this.v2;});
- late String v3 =
- init("No woman", "no cry", (){this.v3 = "Lily was here"; this.v3;});
+ static late String s =
+ init("No woman", "no cry", (){C.s = "Lily was here"; C.s;});
}
-late final String g1 =
- init("No woman", "no cry", (){g1 = "Lily was here"; g1;});
-late String g2 =
- init("No woman", "no cry", (){g2 = "Lily was here"; g2;});
+late String g =
+ init("No woman", "no cry", (){g = "Lily was here"; g;});
main() {
- late final String l1 =
- init("No woman", "no cry", (){l1 = "Lily was here"; l1;);
- late String l2 = init("No woman", "no cry", (){l2 = "Lily was here"; l2;});
-
Expect.equals("", _log);
- Expect.equals("no cry", C.s1);
+ Expect.equals("no cry", C.s);
Expect.equals("counter: 1", _log);
clear();
- Expect.equals("no cry", C.s2);
- Expect.equals("counter: 1", _log);
- clear();
-
- C c = new C();
- Expect.equals("", _log);
-
- Expect.equals("no cry", c.v1);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", c.v2);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", c.v3);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", g1);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", g2);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", l1);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", l2);
+ Expect.equals("no cry", g);
Expect.equals("counter: 1", _log);
}
diff --git a/LanguageFeatures/nnbd/late_A05_t04.dart b/LanguageFeatures/nnbd/late_A05_t04.dart
index 5f1834c..d20140f 100644
--- a/LanguageFeatures/nnbd/late_A05_t04.dart
+++ b/LanguageFeatures/nnbd/late_A05_t04.dart
@@ -35,68 +35,24 @@
}
void clear() {
+ _log = "";
_counter = 0;
}
class C {
- static late final String? s1 =
- init("No woman", "no cry", (){C.s1 = "Lily was here"; C.s1;});
- static late String? s2 =
- init("No woman", "no cry", (){C.s2 = "Lily was here"; C.s2;});
- covariant late String? v1 =
- init("No woman", "no cry", (){this.v1 = "Lily was here"; this.v1;});
- late final String? v2 =
- init("No woman", "no cry", (){this.v2 = "Lily was here"; this.v2;});
- late String? v3 =
- init("No woman", "no cry", (){this.v3 = "Lily was here"; this.v3;});
+ static late String? s =
+ init("No woman", "no cry", (){C.s = "Lily was here"; C.s;});
}
-late final String? g1 =
- init("No woman", "no cry", (){g1 = "Lily was here"; g1;});
-late String? g2 =
- init("No woman", "no cry", (){g2 = "Lily was here"; g2;});
+late String? g =
+ init("No woman", "no cry", (){g = "Lily was here"; g;});
main() {
- late final String? l1 =
- init("No woman", "no cry", (){l1 = "Lily was here"; l1;);
- late String? l2 = init("No woman", "no cry", (){l2 = "Lily was here"; l2;});
-
Expect.equals("", _log);
- Expect.equals("no cry", C.s1);
+ Expect.equals("no cry", C.s);
Expect.equals("counter: 1", _log);
clear();
- Expect.equals("no cry", C.s2);
- Expect.equals("counter: 1", _log);
- clear();
-
- C c = new C();
- Expect.equals("", _log);
-
- Expect.equals("no cry", c.v1);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", c.v2);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", c.v3);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", g1);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", g2);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", l1);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", l2);
+ Expect.equals("no cry", g);
Expect.equals("counter: 1", _log);
}
diff --git a/LanguageFeatures/nnbd/late_A05_t05.dart b/LanguageFeatures/nnbd/late_A05_t05.dart
deleted file mode 100644
index 65a144d..0000000
--- a/LanguageFeatures/nnbd/late_A05_t05.dart
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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 a variable or field is read from during the process of evaluating its own
- * initializer expression, and no write to the variable has occurred, the read
- * is treated as a first read and the initializer expression is evaluated again.
- *
- * @description Check that if a variable or field is read from during the
- * process of evaluating its own initializer expression, and no write to the
- * variable has occurred, the read is treated as a first read and the
- * initializer expression is evaluated again
- * @author sgrekhov@unipro.ru
- */
-// SharedOptions=--enable-experiment=non-nullable
-import "../../Utils/expect.dart";
-
-String _log = "";
-int _counter = 0;
-
-String init(String val, void readme()) {
- _counter++;
- _log = "init('$val'), counter: $_counter";
- if (_counter == 1) {
- readme();
- throw new Exception();
- }
- return val;
-}
-
-void clear() {
- _counter = 0;
-}
-
-class C {
- covariant late String v1;
- late final String v2;
- late String v3;
-
- C() : v1 = init("Lily", (){this.v1;}),
- v2 = init("was", (){this.v2;}),
- v3 = init("here", (){this.v3;});
-}
-
-main() {
- C c = new C();
- Expect.equals("", _log);
-
- Expect.throws(() {c.v1;});
- Expect.equals("Lily", c.v1);
- Expect.equals("init('Lily'), counter: 2", _log);
- clear();
-
- Expect.throws(() {c.v2;});
- Expect.equals("was", c.v2);
- Expect.equals("init('was'), counter: 2", _log);
- clear();
-
- Expect.throws(() {c.v3;});
- Expect.equals("here", c.v3);
- Expect.equals("init('here'), counter: 2", _log);
-}
diff --git a/LanguageFeatures/nnbd/late_A05_t06.dart b/LanguageFeatures/nnbd/late_A05_t06.dart
deleted file mode 100644
index 0ccbec6..0000000
--- a/LanguageFeatures/nnbd/late_A05_t06.dart
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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 a variable or field is read from during the process of evaluating its own
- * initializer expression, and no write to the variable has occurred, the read
- * is treated as a first read and the initializer expression is evaluated again.
- *
- * @description Check that if a variable or field is read from during the
- * process of evaluating its own initializer expression, and no write to the
- * variable has occurred, the read is treated as a first read and the
- * initializer expression is evaluated again
- * @author sgrekhov@unipro.ru
- */
-// SharedOptions=--enable-experiment=non-nullable
-import "../../Utils/expect.dart";
-
-String _log = "";
-int _counter = 0;
-
-String init(String? val, void readme()) {
- _counter++;
- _log = "init('$val'), counter: $_counter";
- if (_counter == 1) {
- readme();
- throw new Exception();
- }
- return val;
-}
-
-void clear() {
- _counter = 0;
-}
-
-class C {
- covariant late String? v1;
- late final String? v2;
- late String? v3;
-
- C() : v1 = init("Lily", (){this.v1;}),
- v2 = init("was", (){this.v2;}),
- v3 = init("here", (){this.v3;});
-}
-
-main() {
- C c = new C();
- Expect.equals("", _log);
-
- Expect.throws(() {c.v1;});
- Expect.equals("Lily", c.v1);
- Expect.equals("init('Lily'), counter: 2", _log);
- clear();
-
- Expect.throws(() {c.v2;});
- Expect.equals("was", c.v2);
- Expect.equals("init('was'), counter: 2", _log);
- clear();
-
- Expect.throws(() {c.v3;});
- Expect.equals("here", c.v3);
- Expect.equals("init('here'), counter: 2", _log);
-}
diff --git a/LanguageFeatures/nnbd/late_A05_t07.dart b/LanguageFeatures/nnbd/late_A05_t07.dart
deleted file mode 100644
index 21d8a20..0000000
--- a/LanguageFeatures/nnbd/late_A05_t07.dart
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 a variable or field is read from during the process of evaluating its own
- * initializer expression, and no write to the variable has occurred, the read
- * is treated as a first read and the initializer expression is evaluated again.
- *
- * @description Check that if a variable or field is read from during the
- * process of evaluating its own initializer expression, and no write to the
- * variable has occurred, the read is treated as a first read and the
- * initializer expression is evaluated again
- * @author sgrekhov@unipro.ru
- */
-// SharedOptions=--enable-experiment=non-nullable
-import "../../Utils/expect.dart";
-
-String _log = "";
-int _counter = 0;
-
-String init(String val1, String val2, void writeAndReadme()) {
- _counter++;
- _log = "counter: $_counter";
- if (_counter == 1) {
- writeAndReadme();
- return val2;
- }
- return val1;
-}
-
-void clear() {
- _counter = 0;
-}
-
-class C {
- covariant late String v1;
- late final String v2;
- late String v3;
-
- C() : v1 = init("No woman", "no cry", (){this.v1 = "Lily was here"; this.v1;}),
- v2 = init("No woman", "no cry", (){this.v2 = "Lily was here"; this.v2;}),
- v3 = init("No woman", "no cry", (){this.v3 = "Lily was here"; this.v3;});
-}
-
-main() {
- C c = new C();
- Expect.equals("", _log);
-
- Expect.equals("no cry", c.v1);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", c.v2);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", c.v3);
- Expect.equals("counter: 1", _log);
-}
diff --git a/LanguageFeatures/nnbd/late_A05_t08.dart b/LanguageFeatures/nnbd/late_A05_t08.dart
deleted file mode 100644
index 3c02057..0000000
--- a/LanguageFeatures/nnbd/late_A05_t08.dart
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 a variable or field is read from during the process of evaluating its own
- * initializer expression, and no write to the variable has occurred, the read
- * is treated as a first read and the initializer expression is evaluated again.
- *
- * @description Check that if a variable or field is read from during the
- * process of evaluating its own initializer expression, and no write to the
- * variable has occurred, the read is treated as a first read and the
- * initializer expression is evaluated again
- * @author sgrekhov@unipro.ru
- */
-// SharedOptions=--enable-experiment=non-nullable
-import "../../Utils/expect.dart";
-
-String _log = "";
-int _counter = 0;
-
-String init(String? val1, String? val2, void writeAndReadme()) {
- _counter++;
- _log = "counter: $_counter";
- if (_counter == 1) {
- writeAndReadme();
- return val2;
- }
- return val1;
-}
-
-void clear() {
- _counter = 0;
-}
-
-class C {
- covariant late String? v1;
- late final String? v2;
- late String? v3;
-
- C() : v1 = init("No woman", "no cry", (){this.v1 = "Lily was here"; this.v1;}),
- v2 = init("No woman", "no cry", (){this.v2 = "Lily was here"; this.v2;}),
- v3 = init("No woman", "no cry", (){this.v3 = "Lily was here"; this.v3;});
-}
-
-main() {
- C c = new C();
- Expect.equals("", _log);
-
- Expect.equals("no cry", c.v1);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", c.v2);
- Expect.equals("counter: 1", _log);
- clear();
-
- Expect.equals("no cry", c.v3);
- Expect.equals("counter: 1", _log);
-}
diff --git a/LanguageFeatures/nnbd/late_A06_t03.dart b/LanguageFeatures/nnbd/late_A06_t03.dart
index 361a0a8..2ab8f87 100644
--- a/LanguageFeatures/nnbd/late_A06_t03.dart
+++ b/LanguageFeatures/nnbd/late_A06_t03.dart
@@ -34,9 +34,9 @@
main() {
A a = new A("No woman", "no cry");
Expect.equals("No woman", a.a1);
- Expect.equals("No cry", a.a2);
+ Expect.equals("no cry", a.a2);
C c = new C("No woman", "no cry");
Expect.equals("No woman", c.c1);
- Expect.equals("No cry", c.c2);
+ Expect.equals("no cry", c.c2);
}
diff --git a/LanguageFeatures/nnbd/late_A06_t04.dart b/LanguageFeatures/nnbd/late_A06_t04.dart
index 061e491..469cb90 100644
--- a/LanguageFeatures/nnbd/late_A06_t04.dart
+++ b/LanguageFeatures/nnbd/late_A06_t04.dart
@@ -14,6 +14,7 @@
* write attempt to this field or variable is not an error, but the second
* attempt of write to it is a runtime error
* @author sgrekhov@unipro.ru
+ * @issue 39802
*/
// SharedOptions=--enable-experiment=non-nullable
import "../../Utils/expect.dart";
diff --git a/LanguageFeatures/nnbd/late_A06_t05.dart b/LanguageFeatures/nnbd/late_A06_t05.dart
index 9b9b9ef..9d9883a 100644
--- a/LanguageFeatures/nnbd/late_A06_t05.dart
+++ b/LanguageFeatures/nnbd/late_A06_t05.dart
@@ -14,6 +14,7 @@
* write attempt to this field or variable is not an error, but the second
* attempt of write to it is a runtime error
* @author sgrekhov@unipro.ru
+ * @issue 39802
*/
// SharedOptions=--enable-experiment=non-nullable
import "../../Utils/expect.dart";
diff --git a/LanguageFeatures/nnbd/late_A06_t06.dart b/LanguageFeatures/nnbd/late_A06_t06.dart
index e069def..a0d9f69 100644
--- a/LanguageFeatures/nnbd/late_A06_t06.dart
+++ b/LanguageFeatures/nnbd/late_A06_t06.dart
@@ -37,11 +37,11 @@
Expect.throws(() {a.a1 = "Lily was here";});
Expect.throws(() {a.a2 = "Lily was here";});
Expect.equals("No woman", a.a1);
- Expect.equals("No cry", a.a2);
+ Expect.equals("no cry", a.a2);
C c = new C("No woman", "no cry");
Expect.throws(() {c.c1 = "Lily was here";});
Expect.throws(() {c.c2 = "Lily was here";});
Expect.equals("No woman", c.c1);
- Expect.equals("No cry", c.c2);
+ Expect.equals("no cry", c.c2);
}
diff --git a/LanguageFeatures/nnbd/late_A07_t01.dart b/LanguageFeatures/nnbd/late_A07_t01.dart
index 4cc30b0..989ea38 100644
--- a/LanguageFeatures/nnbd/late_A07_t01.dart
+++ b/LanguageFeatures/nnbd/late_A07_t01.dart
@@ -4,13 +4,13 @@
* BSD-style license that can be found in the LICENSE file.
*/
/**
- * @assertion Overriding a field which is marked both final and late with a
- * member which does not otherwise introduce a setter introduces an implicit
- * setter which throws.
+ * @assertion A non-local late variable declaration D implicitly induces a
+ * getter into the enclosing scope. It also induces an implicit setter iff one
+ * of the following conditions is satisfied:
+ * - D is non-final.
+ * - D is late, final, and has no initializing expression.
*
- * @description Check that overriding a field which is marked both final and
- * late with a member which does not otherwise introduce a setter introduces an
- * implicit setter which throws.
+ * @description Check overriding of an implicit setter
* @author sgrekhov@unipro.ru
*/
// SharedOptions=--enable-experiment=non-nullable
@@ -21,16 +21,21 @@
late final int? y;
}
class B extends A {
- int get x => 3;
- int? get y => 3;
+ int get x => 1;
+ int? get y => 1;
}
class C extends A {
- late final int x = 3;
- late final int y = 3;
+ late final int x = 2;
+ late final int? y = 2;
}
-void test() {
- Expect.throws(() => new B().x = 3);
- Expect.throws(() => new C().x = 3);
- Expect.throws(() => new B().y = 3);
- Expect.throws(() => new C().y = 3);
+
+void main() {
+ B b = new B();
+ b.x = 3;
+ Expect.throws(() => b.x = 14, (e) => e is LateInitializationError);
+ Expect.throws(() => new C().x = 3, (e) => e is LateInitializationError);
+
+ b.y = 3;
+ Expect.throws(() => b.y = 14, (e) => e is LateInitializationError);
+ Expect.throws(() => new C().y = 3, (e) => e is LateInitializationError);
}
diff --git a/LanguageFeatures/nnbd/late_A07_t02.dart b/LanguageFeatures/nnbd/late_A07_t02.dart
new file mode 100644
index 0000000..e150800
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A07_t02.dart
@@ -0,0 +1,38 @@
+/*
+ * 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 non-local late variable declaration D implicitly induces a
+ * getter into the enclosing scope. It also induces an implicit setter iff one
+ * of the following conditions is satisfied:
+ * - D is non-final.
+ * - D is late, final, and has no initializing expression.
+ *
+ * @description Check overriding of an implicit setter
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+
+class A {
+ late final int x;
+}
+class B extends A {
+ int x = 3;
+}
+class C extends A {
+ late final int x = 3;
+}
+
+void main() {
+ B b = new B();
+ b.x = 3;
+ b.x = 14;
+
+ A a = new B();
+ a.x = 42;
+ a.x = 41;
+ Expect.throws(() => new C().x = 3);
+}
diff --git a/LanguageFeatures/nnbd/late_A08_t01.dart b/LanguageFeatures/nnbd/late_A08_t01.dart
index d8e0029..aee77b4 100644
--- a/LanguageFeatures/nnbd/late_A08_t01.dart
+++ b/LanguageFeatures/nnbd/late_A08_t01.dart
@@ -40,7 +40,7 @@
main() {
Expect.equals("", _log);
- Expect.equals("When", C.s1);
+ Expect.equals("No", C.s1);
Expect.equals("init('No')", _log);
clear();
diff --git a/LanguageFeatures/nnbd/late_A08_t02.dart b/LanguageFeatures/nnbd/late_A08_t02.dart
index 017bdf5..be94102 100644
--- a/LanguageFeatures/nnbd/late_A08_t02.dart
+++ b/LanguageFeatures/nnbd/late_A08_t02.dart
@@ -40,7 +40,7 @@
main() {
Expect.equals("", _log);
- Expect.equals("When", C.s1);
+ Expect.equals("No", C.s1);
Expect.equals("init('No')", _log);
clear();
diff --git a/LanguageFeatures/nnbd/late_A08_t05.dart b/LanguageFeatures/nnbd/late_A08_t05.dart
index 3756a4b..ac578fa 100644
--- a/LanguageFeatures/nnbd/late_A08_t05.dart
+++ b/LanguageFeatures/nnbd/late_A08_t05.dart
@@ -19,13 +19,29 @@
// SharedOptions=--enable-experiment=non-nullable
import "../../Utils/expect.dart";
+const MAX = 10;
+int counter = 0;
+
class C {
- static String s = ((s = "Lily") == s ? "was" : "here");
+ static String s = initS();
+ static String initS() {
+ if (++counter > MAX) {
+ return "result $counter";
+ }
+ return s;
+ }
}
-String g2 = ((g = "Lily") == g ? "was" : "here");
+String g = initG();
+String initG() {
+ if (++counter > MAX) {
+ return "result $counter";
+ }
+ return g;
+}
main() {
- Expect.equals("was", C.s);
- Expect.equals("was", g);
+ Expect.equals("result 11", C.s);
+ counter = 0;
+ Expect.equals("result 11", g);
}
diff --git a/LanguageFeatures/nnbd/late_A08_t06.dart b/LanguageFeatures/nnbd/late_A08_t06.dart
new file mode 100644
index 0000000..4a1aa6c
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A08_t06.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 toplevel or static variable with an initializer is evaluated as
+ * if it was marked late. Note that this is a change from pre-NNBD semantics in
+ * that:
+ * - Throwing an exception during initializer evaluation no longer sets the
+ * variable to null
+ * - Reading the variable during initializer evaluation is no longer checked
+ * for, and does not cause an error.
+ *
+ * @description Check that reading the variable during initializer evaluation is
+ * no longer checked for, and does not cause an error.
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+
+const MAX = 10;
+int counter = 0;
+
+class C {
+ static String? s = initS();
+ static String? initS() {
+ if (++counter > MAX) {
+ return "result $counter";
+ }
+ return s;
+ }
+}
+
+String? g = initG();
+String? initG() {
+ if (++counter > MAX) {
+ return "result $counter";
+ }
+ return g;
+}
+
+main() {
+ Expect.equals("result 11", C.s);
+ counter = 0;
+ Expect.equals("result 11", g);
+}
diff --git a/LanguageFeatures/nnbd/late_A09_t01.dart b/LanguageFeatures/nnbd/late_A09_t01.dart
new file mode 100644
index 0000000..9ea9d82
--- /dev/null
+++ b/LanguageFeatures/nnbd/late_A09_t01.dart
@@ -0,0 +1,43 @@
+/*
+ * 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 The modifier late is added as a built-in identifier.
+ *
+ * @description Check that legacy variable can be declared 'late'
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=non-nullable
+import "../../Utils/expect.dart";
+import "legacy_lib.dart";
+
+class X {
+ static late final A s1;
+ static late A s2;
+
+ late final A v1;
+ late A v2;
+}
+
+late final A g1;
+late A g2;
+
+main() {
+ late final A l1;
+ late A l2;
+
+ X.s1 = new A();
+ X.s2 = new A();
+
+ X x = new X();
+ x.v1 = new A();
+ x.v2 = new A();
+
+ g1 = new A();
+ g2 = new A();
+
+ l1 = new A();
+ l2 = new A();
+}