Issue #1087: New tests for unnamed constructor tear offs added
diff --git a/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t01.dart b/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t01.dart
index 37e6c5d..fe2983c 100644
--- a/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t01.dart
+++ b/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t01.dart
@@ -18,11 +18,9 @@
import "../../Utils/expect.dart";
class C {
- C() {}
C.constr() {}
}
main() {
Expect.isTrue(C.constr is C Function());
- Expect.isTrue(C.new is C Function());
}
diff --git a/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t02.dart b/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t02.dart
index e5226b9..fa83630 100644
--- a/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t02.dart
+++ b/LanguageFeatures/Constructor-tear-offs/named_constructor_A02_t02.dart
@@ -18,17 +18,11 @@
import "../../Utils/expect.dart";
class C<T> {
- C() {}
C.constr(T t) {}
}
main() {
Expect.isTrue(C.constr is C Function<X extends dynamic>(X));
- Expect.isTrue(C.new is C Function<X extends dynamic>());
-
Expect.isTrue(C<int>.constr is C Function<X extends int>(X));
- Expect.isTrue(C<int>.new is C Function<X extends int>());
-
Expect.isTrue(C.constr<int> is C Function<T extends int>(T));
- Expect.isTrue(C.new<int> is C Function<T extends int>());
}
diff --git a/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A04_t01.dart b/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A04_t01.dart
new file mode 100644
index 0000000..8a44c5d
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A04_t01.dart
@@ -0,0 +1,24 @@
+// 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 The tear-off cannot be performed without the [.new] because that
+/// expression already means something else.
+///
+/// @description Check that the tear-off cannot be performed without the [.new]:
+/// tests default constructor call
+/// @author iarkh@unipro.ru
+
+// SharedOptions=--enable-experiment=constructor-tearoffs
+
+class C {
+ C() {}
+}
+
+main() {
+ var v = C;
+ C c = v();
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
+}
diff --git a/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A04_t02.dart b/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A04_t02.dart
new file mode 100644
index 0000000..f38b79d
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A04_t02.dart
@@ -0,0 +1,30 @@
+// 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 The tear-off cannot be performed without the [.new] because that
+/// expression already means something else.
+///
+/// @description Check that the tear-off cannot be performed without the [.new]:
+/// tests default constructor call
+/// @author iarkh@unipro.ru
+
+// SharedOptions=--enable-experiment=constructor-tearoffs
+
+class C<X> {
+ C(int a, String b, c) {}
+}
+
+main() {
+ var v = C;
+ C c = v(1, "", null);
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+ var v1 = C.C;
+// ^
+// [analyzer] unspecified
+// [cfe] unspecified
+
+}
diff --git a/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A05_t01.dart b/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A05_t01.dart
new file mode 100644
index 0000000..66d8541
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A05_t01.dart
@@ -0,0 +1,23 @@
+// 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 With regard to tear-offs, [C.new] works exactly as if it had been
+/// a named constructor, with a corresponding constructor function named
+/// [C.new$tearoff].
+///
+/// @description Check that [C.new] tearing off works exactly as a corresponding
+/// construction function named [C.new$tearoff].
+/// @author iarkh@unipro.ru
+
+// SharedOptions=--enable-experiment=constructor-tearoffs
+
+import "../../Utils/expect.dart";
+
+class C {
+ C() {}
+}
+
+main() {
+ Expect.isTrue(C.new is C Function());
+}
\ No newline at end of file
diff --git a/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A05_t02.dart b/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A05_t02.dart
new file mode 100644
index 0000000..65e3d9c
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A05_t02.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.
+
+/// @assertion A named constructor tear-off expression of one of the forms above
+/// evaluates to a function value which could be created by tearing off a
+/// corresponding constructor function, which would be a static function defined
+/// on the class denoted by [C], with a fresh name here represented by adding
+/// [$tearoff]:
+///
+/// static C name$tearoff<typeParams>(params) => C<typeArgs>.name(args);
+///
+/// @description Checks constructor tear-off expression for generic class.
+/// @author iarkh@unipro.ru
+
+// SharedOptions=--enable-experiment=constructor-tearoffs
+
+import "../../Utils/expect.dart";
+
+class C<T> {
+ C(int i, T t) {}
+}
+
+main() {
+ Expect.isTrue(C.new is C Function<X>(int i, X d));
+ Expect.isTrue(C<int>.new is C Function<X extends int>(int i, X d));
+ Expect.isTrue(C.new<int> is C Function<T extends int>(int i, X d));
+}
diff --git a/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A06_t01.dart b/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A06_t01.dart
new file mode 100644
index 0000000..6382a00
--- /dev/null
+++ b/LanguageFeatures/Constructor-tear-offs/unnamed_constructor_A06_t01.dart
@@ -0,0 +1,43 @@
+// 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 In [dart:mirrors], the name of the constructor is still just [C],
+/// not [C.new] (that's not a valid symbol, and we don't want to break existing
+/// reflection using code).
+///
+/// @description Checks that the name of the constructor in [dart::mirrors] is
+/// [C].
+/// @author iarkh@unipro.ru
+
+// SharedOptions=--enable-experiment=constructor-tearoffs
+
+import "../../Utils/expect.dart";
+import 'dart:mirrors';
+
+class C {
+ int x;
+ C(this.x);
+
+ checkName() {
+ bool found = false;
+ ClassMirror classMirror = reflect(C(1)).type;
+ for (var v in classMirror.declarations.values) {
+ String name = MirrorSystem.getName(v.simpleName);
+ found = name == "C";
+ if(name == "new") {
+ Expect.fail("Constructor name is new");
+ }
+ }
+ Expect.isTrue(found);
+ }
+}
+
+void main() {
+ C(1).checkName();
+
+ C.new(1).checkName();
+
+ var v = C.new;
+ v(1).checkName();
+}