Issue #1087: New tests for Tearing off constructors from type aliases added.
diff --git a/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t01.dart b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t01.dart
index dfe743e..c5f8ab0 100644
--- a/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t01.dart
+++ b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t01.dart
@@ -2,27 +2,26 @@
// 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 With generalized type-aliases, it's possible to declare a
-/// class-alias like [typedef IntList = List<int>;]. ... It's constant and
-/// canonicalized to the same function as [List<int>.filled]. In other words,
-/// the alias is treated as an actual alias for the type it aliases.
+/// @assertion This differs for a generic type alias. If the type alias is
+/// instantiated (implicitly or explicitly), then the result is still the same
+/// as tearing off the aliased type directly, and it's constant and
+/// canonicalized if the type arguments are constant.
///
-/// @description Checks that class-alias [typedef IntList = List] is
-/// constant and canonicalized. Tests raw [List] class.
+/// @description Checks that if type alias is instantiated, the result is the
+/// same as tearing off the aliased type directly.
+///
/// @author iarkh@unipro.ru
import "../../Utils/expect.dart";
-typedef IntList = List;
+typedef MyList<T> = List<T>;
main() {
- var v1 = IntList.filled;
- var v2 = IntList.filled;
- var v3 = IntList.filled;
+ var v1 = MyList<int>.filled;
+ List list1 = v1(3, 1);
+ Expect.equals([1, 1, 1], list1);
- Expect.identical(v1, v2);
- Expect.identical(v1, v3);
-
- var v4 = (IntList.filled);
- Expect.identical(v1, v4);
+ var v2 = MyList<String>.filled;
+ List list2 = v2(3, "abc");
+ Expect.equals(["abc", "abc", "abc"], list1);
}
diff --git a/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t02.dart b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t02.dart
index 94e22a7..cd8703b 100644
--- a/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t02.dart
+++ b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t02.dart
@@ -2,65 +2,33 @@
// 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 With generalized type-aliases, it's possible to declare a
-/// class-alias like [typedef IntList = List<int>;]. ... It's constant and
-/// canonicalized to the same function as [List<int>.filled]. In other words,
-/// the alias is treated as an actual alias for the type it aliases.
+/// @assertion This differs for a generic type alias. If the type alias is
+/// instantiated (implicitly or explicitly), then the result is still the same
+/// as tearing off the aliased type directly, and it's constant and
+/// canonicalized if the type arguments are constant.
///
-/// @description Checks that class-alias [typedef IntList = List] is
-/// constant and canonicalized. Tests raw [List] class.
+/// @description Checks that if type alias is instantiated, the result is the
+/// same as tearing off the aliased type directly. Test negative static cases.
+///
/// @author iarkh@unipro.ru
-import "../../Utils/expect.dart";
+typedef MyList<T> = List<T>;
-class A<T extends num> {
- T? i, j;
- A();
- A.constr(this.i, this.j);
-}
+main() {
+ var v = MyList<int>.filled;
+ v(3, "");
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
-typedef IntList = List;
+ var v1 = MyList<String>.filled;
+ v1(3, null);
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
-typedef AAlias = A<int>;
-
-testList() {
- var v1 = IntList.filled;
- var v2 = IntList.filled;
- var v3 = IntList.filled;
-
- Expect.identical(v1, v2);
- Expect.identical(v1, v3);
-
- var v4 = (IntList.filled);
- Expect.identical(v1, v4);
-}
-
-testA_new() {
- var v1 = A.new;
- var v2 = A.new;
- var v3 = A.new;
-
- Expect.identical(v1, v2);
- Expect.identical(v1, v3);
-
- var v4 = (A.new);
- Expect.identical(v1, v4);
-}
-
-testA_constr() {
- var v1 = A.constr;
- var v2 = A.constr;
- var v3 = A.constr;
-
- Expect.identical(v1, v2);
- Expect.identical(v1, v3);
-
- var v4 = (A.constr);
- Expect.identical(v1, v4);
-}
-
-void main() {
- testList();
- testA_new();
- testA_constr();
+ v1(3, 4);
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
}
diff --git a/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t03.dart b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t03.dart
new file mode 100644
index 0000000..e188cb9
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t03.dart
@@ -0,0 +1,25 @@
+// Copyright (c) 2021, 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 This differs for a generic type alias. If the type alias is
+/// instantiated (implicitly or explicitly), then the result is still the same
+/// as tearing off the aliased type directly, and it's constant and
+/// canonicalized if the type arguments are constant.
+///
+/// @description Checks that if type alias is instantiated, the result is the
+/// same as tearing off the aliased type directly. Test negative runtime cases.
+///
+/// @author iarkh@unipro.ru
+
+import "../../Utils/expect.dart";
+
+typedef MyList<T> = List<T>;
+
+dynamic d = 1;
+
+main() {
+ var v = MyList<String>.filled;
+ Expect.throws(() { v(2, d); });
+ Expect.throws(() { v(2, null as dynamic); });
+}
diff --git a/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t04.dart b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t04.dart
new file mode 100644
index 0000000..2fe4238
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t04.dart
@@ -0,0 +1,27 @@
+// Copyright (c) 2021, 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 This differs for a generic type alias. If the type alias is
+/// instantiated (implicitly or explicitly), then the result is still the same
+/// as tearing off the aliased type directly, and it's constant and
+/// canonicalized if the type arguments are constant.
+///
+/// @description Checks that if type alias is instantiated, the result is the
+/// same as tearing off the aliased type directly.
+///
+/// @author iarkh@unipro.ru
+
+import "../../Utils/expect.dart";
+
+typedef MyList<T extends num> = List<T>;
+
+main() {
+ var v1 = MyList<num>.filled;
+ List list1 = v1(3, 1.5);
+ Expect.equals([1, 1, 1], list1);
+
+ var v2 = MyList<int>.filled;
+ List list2 = v2(3, 1);
+ Expect.equals([1, 1, 1], list1);
+}
diff --git a/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t05.dart b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t05.dart
new file mode 100644
index 0000000..b23bf91
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t05.dart
@@ -0,0 +1,39 @@
+// Copyright (c) 2021, 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 This differs for a generic type alias. If the type alias is
+/// instantiated (implicitly or explicitly), then the result is still the same
+/// as tearing off the aliased type directly, and it's constant and
+/// canonicalized if the type arguments are constant.
+///
+/// @description Checks that if type alias is instantiated, the result is the
+/// same as tearing off the aliased type directly. Test negative static cases.
+///
+/// @author iarkh@unipro.ru
+
+typedef MyList<T extends num> = List<T>;
+
+main() {
+ var v = MyList<num>.filled;
+ v(3, "");
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ var v1 = MyList<int>.filled;
+ v1(3, null);
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ v1(7, 4.3);
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ var v = MyList<String>.filled;
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
diff --git a/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t06.dart b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t06.dart
new file mode 100644
index 0000000..0cf2c02
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t06.dart
@@ -0,0 +1,31 @@
+// Copyright (c) 2021, 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 This differs for a generic type alias. If the type alias is
+/// instantiated (implicitly or explicitly), then the result is still the same
+/// as tearing off the aliased type directly, and it's constant and
+/// canonicalized if the type arguments are constant.
+///
+/// @description Checks that if type alias is instantiated, the result is the
+/// same as tearing off the aliased type directly. Test negative runtime cases.
+///
+/// @author iarkh@unipro.ru
+
+import "../../Utils/expect.dart";
+
+typedef MyList<T extends num> = List<T>;
+
+dynamic d = 3.14;
+String s = "";
+
+main() {
+ var v = MyList<num>.filled;
+ Expect.throws(() { v(2, s); });
+
+ var v1 = MyList<int>.filled;
+ Expect.throws(() { v1(7, d); });
+ Expect.throws(() { v1(1, s); });
+ Expect.throws(() { v1(7, null as dynamic); });
+ Expect.throws(() { v1(3, 1.0 as dynamic); });
+}
diff --git a/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t07.dart b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t07.dart
new file mode 100644
index 0000000..5c08fa7
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A03_t07.dart
@@ -0,0 +1,35 @@
+// Copyright (c) 2021, 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 This differs for a generic type alias. If the type alias is
+/// instantiated (implicitly or explicitly), then the result is still the same
+/// as tearing off the aliased type directly, and it's constant and
+/// canonicalized if the type arguments are constant.
+///
+/// @description Checks that the result of generic type alias tearing off is
+/// constant and canonicalized when the alias is instantiated.
+///
+/// @author iarkh@unipro.ru
+
+import "../../Utils/expect.dart";
+
+typedef MyList<T extends num> = List<T>;
+
+main() {
+ var v1 = MyList<num>.filled;
+ var v2 = MyList<num>.filled;
+ var v3 = (MyList<num>).filled;
+
+ Expect.identical(v1, v2);
+ Expect.identical(v1, v3);
+
+ var v4 = MyList<int>.filled;
+ var v5 = MyList<int>.filled;
+ var v6 = (MyList<int>).filled;
+
+ Expect.identical(v4, v5);
+ Expect.identical(v4, v6);
+
+ Expect.notEquals(v1, v4);
+}
diff --git a/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A04_t01.dart b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A04_t01.dart
new file mode 100644
index 0000000..2057742
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A04_t01.dart
@@ -0,0 +1,28 @@
+// Copyright (c) 2021, 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.
+
+/// If the type alias is not instantiated, then it's a function from types to
+/// types, not an alias for a single type, and tearing off a constructor works
+/// equivalently to tearing off a corresponding generic function where the
+/// generics match the type alias, not the underlying class. The result is a
+/// compile-time constant.
+///
+/// @description Checks that if type alias is not instantiated, tearing off a
+/// constructor works equivalently to tearing off a corresponding generic
+/// function where the generics match the type alias.
+///
+/// @author iarkh@unipro.ru
+
+import "../../Utils/expect.dart";
+
+typedef MyList<T> = List<T>;
+
+main() {
+ var v = MytList.filled;
+ List list1 = v(3, 1);
+ Expect.equals([1, 1, 1], list1);
+
+ List list2 = v(4, null);
+ Expect.equals([null, null, null, null], list1);
+}
diff --git a/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A04_t02.dart b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A04_t02.dart
new file mode 100644
index 0000000..b64d3f7
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A04_t02.dart
@@ -0,0 +1,27 @@
+// Copyright (c) 2021, 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.
+
+/// If the type alias is not instantiated, then it's a function from types to
+/// types, not an alias for a single type, and tearing off a constructor works
+/// equivalently to tearing off a corresponding generic function where the
+/// generics match the type alias, not the underlying class. The result is a
+/// compile-time constant.
+///
+/// @description Checks that the result of the not instantiated type alias
+/// tearing off is a compile-time constant.
+///
+/// @author iarkh@unipro.ru
+
+import "../../Utils/expect.dart";
+
+typedef IntList = List;
+
+main() {
+ var v1 = IntList.filled;
+ var v2 = IntList.filled;
+ var v3 = IntList.filled;
+
+ Expect.identical(v1, v2);
+ Expect.identical(v1, v3);
+}
diff --git a/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A04_t03.dart b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A04_t03.dart
new file mode 100644
index 0000000..690cebc
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/tearing_off_from_typedef_A04_t03.dart
@@ -0,0 +1,68 @@
+// Copyright (c) 2021, 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.
+
+/// If the type alias is not instantiated, then it's a function from types to
+/// types, not an alias for a single type, and tearing off a constructor works
+/// equivalently to tearing off a corresponding generic function where the
+/// generics match the type alias, not the underlying class. The result is a
+/// compile-time constant.
+///
+/// @description Checks that the result of the not instantiated type alias
+/// tearing off is a compile-time constant.
+///
+/// @author iarkh@unipro.ru
+
+import "../../Utils/expect.dart";
+
+class A<T extends num> {
+ T? i, j;
+ A();
+ A.constr(this.i, this.j);
+}
+
+typedef IntList = List;
+
+typedef AAlias = A<int>;
+
+testList() {
+ var v1 = IntList.filled;
+ var v2 = IntList.filled;
+ var v3 = IntList.filled;
+
+ Expect.identical(v1, v2);
+ Expect.identical(v1, v3);
+
+ var v4 = (IntList.filled);
+ Expect.identical(v1, v4);
+}
+
+testA_new() {
+ var v1 = A.new;
+ var v2 = A.new;
+ var v3 = A.new;
+
+ Expect.identical(v1, v2);
+ Expect.identical(v1, v3);
+
+ var v4 = (A.new);
+ Expect.identical(v1, v4);
+}
+
+testA_constr() {
+ var v1 = A.constr;
+ var v2 = A.constr;
+ var v3 = A.constr;
+
+ Expect.identical(v1, v2);
+ Expect.identical(v1, v3);
+
+ var v4 = (A.constr);
+ Expect.identical(v1, v4);
+}
+
+void main() {
+ testList();
+ testA_new();
+ testA_constr();
+}