Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(769)

Unified Diff: tests/language/generic_methods_type_expression_test.dart

Issue 1976213002: Adjusts dart2js backend to handle method type arguments. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Made MethodTypeVariableType malformed, eliminated malformMethodTypeVariableType Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/language/generic_methods_type_expression_test.dart
diff --git a/tests/language/generic_methods_type_expression_test.dart b/tests/language/generic_methods_type_expression_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cbe08026c4f5fb7743a57f4c3e6910d5097ae462
--- /dev/null
+++ b/tests/language/generic_methods_type_expression_test.dart
@@ -0,0 +1,52 @@
+// Copyright (c) 2016, 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.
+//
+// DartOptions=--generic-method-syntax
+
+/// Dart test on the usage of method type arguments in type expressions. With
+/// '--generic-method-syntax', the type argument is available at runtime,
+/// but erased to `dynamic`.
+
+library generic_methods_type_expression_test;
+
+import "package:expect/expect.dart";
+
+bool f1<T>(Object o) => o is T;
+
+bool f2<T>(Object o) => o is List<T>;
+
+bool f3<T>(Object o) => o is! T;
+
+bool f4<T>(Object o) => o is! List<T>;
+
+T f5<T>(Object o) => o as T;
+
+List<T> f6<T>(Object o) => o as List<T>;
+
+Type f7<T>() => T;
+
+class TypeValue<X> {
+ Type get value => X;
+}
+
+Type f8<T>() => new TypeValue<List<T>>().value;
+
+main() {
+ String s = "Hello!";
+ List<String> ss = <String>[s];
+ Expect.throws(() => f1<int>(42), (e) => e is TypeError);
+ Expect.throws(() => f1<String>(42), (e) => e is TypeError);
+ Expect.equals(f2<int>(<int>[42]), true);
+ Expect.equals(f2<String>(<int>[42]), true); // `is List<dynamic>` is true.
+ Expect.throws(() => f3<int>(42), (e) => e is TypeError);
+ Expect.throws(() => f3<String>(42), (e) => e is TypeError);
+ Expect.equals(f4<int>(<int>[42]), false);
+ Expect.equals(f4<String>(<int>[42]), false); // `is! List<dynamic>` is false.
+ Expect.throws(() => f5<String>(s), (e) => e is TypeError);
+ Expect.throws(() => f5<int>(s), (e) => e is TypeError);
+ Expect.equals(f6<String>(ss), ss);
+ Expect.equals(f6<int>(ss), ss); // `as List<dynamic>` succeeds.
+ Expect.throws(() => f7<int>(), (e) => e is TypeError);
+ Expect.equals(f8<int>(), List); // Returns `List<dynamic>`.
+}

Powered by Google App Engine
This is Rietveld 408576698