Issue #477: tests for Constant-2019-update added.
diff --git a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t01.dart b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t01.dart
index b109567..6d9ef69 100644
--- a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t01.dart
+++ b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t01.dart
@@ -7,17 +7,30 @@
* @assertion The [??] operator only evaluates its second operand if the first
* evaluates to [null], and the second operand must be a potentially constant
* expression.
- * @description Checks that operator [??] operators rejects the second operand
- * if the first one is not [null] in constant expression.
+ * @description Checks that operator [??] rejects the second operand if the
+ * first one is not [null] in constant expression.
* @author iarkh@unipro.ru
*/
// SharedOptions=--enable-experiment=constant-update-2018
import "../../Utils/expect.dart";
+const dynamic d1 = "12345";
+const dynamic d2 = 11;
+const int i = 14;
+
main() {
const int a1 = 20 ?? (null as String).length;
Expect.equals(20, a1);
const String a2 = "testme" ?? "wrong";
Expect.equals("testme", a2);
+
+ const int a3 = i ?? d1;
+ Expect.equals(14, a3);
+
+ const int a4 = i ?? d2;
+ Expect.equals(14, a4);
+
+ const a5 = d1 ?? null;
+ Expect.equals(a5, a5);
}
diff --git a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t03.dart b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t03.dart
index d0ac00b..f4c4e8d 100644
--- a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t03.dart
+++ b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t03.dart
@@ -10,11 +10,13 @@
* @description Checks that compile-time exception is thrown if the first
* operand of [??] operator is [null] and the second one is incorrect in the
* constant expression.
- * @compile-error
* @author iarkh@unipro.ru
*/
// SharedOptions=--enable-experiment=constant-update-2018
main() {
const String s1 = null ?? (null as String).length;
+// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
}
diff --git a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t04.dart b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t04.dart
index cc99658..fbc4a2d 100644
--- a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t04.dart
+++ b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t04.dart
@@ -8,13 +8,36 @@
* evaluates to [null], and the second operand must be a potentially constant
* expression.
* @description Checks that compile-time exception is thrown if the first
- * operand of [??] operator is [null] and the second one is incorrect in the
- * constant expression.
- * @compile-error
+ * operand of [??] operator is [null] and the second one has incorrect type in
+ * the constant expression.
* @author iarkh@unipro.ru
*/
// SharedOptions=--enable-experiment=constant-update-2018
+const dynamic d1 = 11;
+const String d2 = "check me here";
+
+const nil = null;
+
main() {
- const String s2 = null ?? 124;
+ const String s1 = null ?? 124;
+// ^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const int i1 = nil ?? "";
+// ^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const String s2 = null ?? d1;
+// ^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const int i2 = nil ?? d2;
+// ^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
}
diff --git a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t07.dart b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t07.dart
index 2b8c1d5..14de9e4 100644
--- a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t07.dart
+++ b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t07.dart
@@ -10,13 +10,15 @@
* @description Checks that operator exception is thrown if the first [??] is
* not [null] and the second one is incorrect in potentially constant
* expression.
- * @compile-error
* @author iarkh@unipro.ru
*/
// SharedOptions=--enable-experiment=constant-update-2018
class MyClass {
final int a;
const MyClass(int i1, String i2) : a = (i1 ?? i2.length + "abc");
+// ^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
}
main() {
diff --git a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t08.dart b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t08.dart
index 9484dd4..f8f1f36 100644
--- a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t08.dart
+++ b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t08.dart
@@ -9,7 +9,6 @@
* expression.
* @description Checks that operator [??] operators does not reject the second
* operand if the first one is [null] in potentially constant expression.
- * @compile-error
* @author iarkh@unipro.ru
*/
// SharedOptions=--enable-experiment=constant-update-2018
@@ -21,4 +20,8 @@
main() {
const MyClass c2 = MyClass(null, "incorrect");
+// ^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
}
diff --git a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t09.dart b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t09.dart
new file mode 100644
index 0000000..211dcdb
--- /dev/null
+++ b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t09.dart
@@ -0,0 +1,52 @@
+/*
+ * 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 [??] operator only evaluates its second operand if the first
+ * evaluates to [null], and the second operand must be a potentially constant
+ * expression.
+ * @description Checks that operator [??] in constant expression throws a
+ * compile error if the first operand is not constant.
+ * @author iarkh@unipro.ru
+ */
+// SharedOptions=--enable-experiment=constant-update-2018
+
+int nonConst_i = 1;
+Null nonConst_null = null;
+dynamic nonConst_null_1 = null;
+dynamic nonConst;
+String nonConst_str = "";
+
+const dynamic d1 = "12345";
+const dynamic d2 = 11;
+const int i = 14;
+
+main() {
+ const int a1 = nonConst_i ?? 1;
+// ^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const a2 = nonConst_null ?? "incorrect";
+// ^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const a3 = nonConst_null_1 ?? "incorrect";
+// ^^^^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const a4 = nonConst ?? 9;
+// ^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const a5 = nonConst_str ?? "145";
+// ^^^^^^^^^^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+}
diff --git a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t10.dart b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t10.dart
new file mode 100644
index 0000000..088e096
--- /dev/null
+++ b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t10.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 [??] operator only evaluates its second operand if the first
+ * evaluates to [null], and the second operand must be a potentially constant
+ * expression.
+ * @description Checks that operator [??] throws a error if the first operand is
+ * [null] and the second one is not a potentially constant.
+ * @author iarkh@unipro.ru
+ */
+// SharedOptions=--enable-experiment=constant-update-2018
+
+dynamic d1 = "12345";
+dynamic d2 = 11;
+int i = 14;
+dynamic d;
+
+const nil = null;
+
+main() {
+ const a1 = null ?? d1;
+// ^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const a2 = nil ?? d2;
+// ^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const a3 = nil ?? i;
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const a4 = nil ?? d;
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
diff --git a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t11.dart b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t11.dart
new file mode 100644
index 0000000..a7e500a
--- /dev/null
+++ b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t11.dart
@@ -0,0 +1,44 @@
+/*
+ * 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 [??] operator only evaluates its second operand if the first
+ * evaluates to [null], and the second operand must be a potentially constant
+ * expression.
+ * @description Checks that operator [??] throws a error if the first operand is
+ * not [null] and the second one is not a potentially constant.
+ * @author iarkh@unipro.ru
+ */
+// SharedOptions=--enable-experiment=constant-update-2018
+
+dynamic d1 = "12345";
+dynamic d2 = 11;
+int i = 14;
+dynamic d;
+
+const const1 = 0;
+const const2 = "testme";
+
+main() {
+ const a1 = const1 ?? d1;
+// ^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const a2 = const2 ?? d2;
+// ^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const a3 = 14 ?? i;
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const a4 = "12345" ?? d;
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
diff --git a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t12.dart b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t12.dart
new file mode 100644
index 0000000..ce6fc0e
--- /dev/null
+++ b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t12.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 [??] operator only evaluates its second operand if the first
+ * evaluates to [null], and the second operand must be a potentially constant
+ * expression.
+ * @description Checks that compile-time exception is thrown if the first
+ * operand of [??] operator is not [null] and the second one has incorrect type
+ * in the constant expression.
+ * @author iarkh@unipro.ru
+ */
+// SharedOptions=--enable-experiment=constant-update-2018
+
+const int i = 1;
+
+const dynamic d1 = 11;
+const String d2 = "check me here";
+
+main() {
+ const String s1 = "" ?? 124;
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const int i1 = i ?? "";
+// ^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const String s2 = d2 ?? d1;
+// ^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const int i2 = d1 ?? d2;
+// ^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+}
diff --git a/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t13.dart b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t13.dart
new file mode 100644
index 0000000..114e40e
--- /dev/null
+++ b/LanguageFeatures/Constant-update-2018/ShortCircuitOperators_A03_t13.dart
@@ -0,0 +1,42 @@
+/*
+ * 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 [??] operator only evaluates its second operand if the first
+ * evaluates to [null], and the second operand must be a potentially constant
+ * expression.
+ * @description Checks that compile-time exception is thrown if the first
+ * operand of [??] operator is of incorrect type.
+ * @author iarkh@unipro.ru
+ */
+// SharedOptions=--enable-experiment=constant-update-2018
+
+const int i = 1;
+
+const String nil = null;
+const String str = "check me here";
+
+main() {
+ const String s1 = 14 ?? "12345";
+// ^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const String s2 = i ?? "12345";
+// ^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const int i1 = "12345" ?? 12345;
+// ^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ const int res = str ?? 12345;
+// ^^^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+}