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

Unified Diff: test/codegen/language/generic_tearoff_test.dart

Issue 1930323004: instantiate generic tear-offs, fixes #525 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: format Created 4 years, 8 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
« no previous file with comments | « lib/src/compiler/code_generator.dart ('k') | tool/input_sdk/private/ddc_runtime/classes.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/codegen/language/generic_tearoff_test.dart
diff --git a/test/codegen/language/generic_tearoff_test.dart b/test/codegen/language/generic_tearoff_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e07ba4360d52d37622dcdb19332a726e7a276acb
--- /dev/null
+++ b/test/codegen/language/generic_tearoff_test.dart
@@ -0,0 +1,44 @@
+// 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.
+
+import 'dart:math' as math;
+import 'dart:math' show min; // <-- generic: <T extends num>(T, T) -> T
+import 'package:expect/expect.dart';
+
+class C {
+ /*=T*/ m/*<T extends num>*/(/*=T*/ x, /*=T*/ y) => min(x, y);
+ int m2(int x, int y) => min(x, y);
+}
+
+typedef int Int2Int2Int(int x, int y);
+
+void _test(Int2Int2Int f) {
+ int y = f(123, 456);
+ Expect.equals(y, 123);
+ // `f` doesn't take type args.
+ Expect.throws(() => (f as dynamic)/*<int>*/(123, 456));
+}
+
+void _testParam(/*=T*/ minFn/*<T extends num>*/(/*=T*/ x, /*=T*/ y)) {
+ _test(minFn);
+}
+
+main() {
+ // Strong mode infers: `min<int>`
+ // Test simple/prefixed identifiers and property access
+ _test(min);
+ _test(math.min);
+ _test(new C().m);
+
+ // Test local function, variable, and parameter
+ /*=T*/ m/*<T extends num>*/(/*=T*/ x, /*=T*/ y) => min(x, y);
+ _test(m);
+ final f = min;
+ _test(f);
+ _testParam(math.min);
+
+ // A few misc tests for methods
+ Expect.equals(123, (new C() as dynamic).m/*<int>*/(123, 456));
+ Expect.throws(() => (new C() as dynamic).m2/*<int>*/(123, 456));
+}
« no previous file with comments | « lib/src/compiler/code_generator.dart ('k') | tool/input_sdk/private/ddc_runtime/classes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698