#401. Tearoff tests added and small fixes
diff --git a/LanguageFeatures/Extension-methods/syntax_member_declarations_t01.dart b/LanguageFeatures/Extension-methods/syntax_member_declarations_t01.dart
index 0e4d954..50ba1e9 100644
--- a/LanguageFeatures/Extension-methods/syntax_member_declarations_t01.dart
+++ b/LanguageFeatures/Extension-methods/syntax_member_declarations_t01.dart
@@ -31,6 +31,7 @@
static void set staticSetter(String v) {staticVar = v;};
static String staticMethod(String s) => s;
static String staticVar = "Run, Forrest, run";
+ static const staticConst = "Nothing is constant, everything is changing";
}
main() {
@@ -47,4 +48,5 @@
Expect.equals("Run, Forrest, run", List.staticVar);
List.staticSetter = "Lily was here";
Expect.equals("Lily was here", List.staticVar);
+ Expect.equals("Nothing is constant, everything is changing", List.staticConst);
}
diff --git a/LanguageFeatures/Extension-methods/syntax_type_t04.dart b/LanguageFeatures/Extension-methods/syntax_type_t04.dart
index da74641..d3b41a6 100644
--- a/LanguageFeatures/Extension-methods/syntax_type_t04.dart
+++ b/LanguageFeatures/Extension-methods/syntax_type_t04.dart
@@ -21,7 +21,7 @@
* single type variable. Test nullable built-in types
* @author sgrekhov@unipro.ru
*/
-// SharedOptions=--enable-experiment=extension-methods
+// SharedOptions=--enable-experiment=extension-methods,non-nullable
extension MyInt on int? {}
diff --git a/LanguageFeatures/Extension-methods/tearoffs_t01.dart b/LanguageFeatures/Extension-methods/tearoffs_t01.dart
new file mode 100644
index 0000000..eb6412a
--- /dev/null
+++ b/LanguageFeatures/Extension-methods/tearoffs_t01.dart
@@ -0,0 +1,26 @@
+/*
+ * 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 static extension method can be torn off like an instance method.
+ *
+ * @description Check that a static extension method can be torn off like an
+ * instance method.
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=extension-methods
+import "../../Utils/expect.dart";
+
+extension ExtendedList on List {
+ int foo<T>(T x) => x.toString().length;
+}
+
+main() {
+ List list = [1, 2, 3];
+ int Function(int) func = list.foo;
+ Expect.equals(3, func([1]));
+ Expect.equals(3, func("[1]"));
+ Expect.equals(13, func("Lily was here"));
+}
diff --git a/LanguageFeatures/Extension-methods/tearoffs_t02.dart b/LanguageFeatures/Extension-methods/tearoffs_t02.dart
new file mode 100644
index 0000000..a0673e1
--- /dev/null
+++ b/LanguageFeatures/Extension-methods/tearoffs_t02.dart
@@ -0,0 +1,28 @@
+/*
+ * 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 Torn off extension methods are never equal unless they are
+ * identical.
+ *
+ * @description Check that a static extension method can be torn off like an
+ * instance method.
+ * @author sgrekhov@unipro.ru
+ */
+// SharedOptions=--enable-experiment=extension-methods
+import "../../Utils/expect.dart";
+
+extension ExtendedList on List {
+ int foo<T>(T x) => x.toString().length;
+}
+
+main() {
+ List list = [1, 2, 3];
+ int Function(int) func1 = list.foo;
+ int Function(int) func2 = list.foo;
+
+ Expect.isFalse(func1 == func2);
+ Expect.isTrue(func1 == func1);
+}