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

Unified Diff: pkg/kernel/testcases/closures/instance_tear_off.dart

Issue 2561723003: Merge kernel closure conversion into the Dart SDK (Closed)
Patch Set: Remove path constraint Created 4 years 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: pkg/kernel/testcases/closures/instance_tear_off.dart
diff --git a/pkg/kernel/testcases/closures/instance_tear_off.dart b/pkg/kernel/testcases/closures/instance_tear_off.dart
new file mode 100644
index 0000000000000000000000000000000000000000..a0c4ce8bfd7da735bff419527564ec5f8ead3df1
--- /dev/null
+++ b/pkg/kernel/testcases/closures/instance_tear_off.dart
@@ -0,0 +1,65 @@
+// 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.md file.
+
+class C {
+ var f = () => "f";
+ get g => (x) => "g($x)";
+ a() => "a";
+ b(x) => x;
+ c(x, [y = 2]) => x + y;
+ d(x, {y: 2}) => x + y;
+}
+
+/// This class doesn't use its type variable.
+class D<T> {
+ var f = () => "f";
+ get g => (x) => "g($x)";
+ a() => "a";
+ b(x) => x;
+ c(x, [y = 2]) => x + y;
+ d(x, {y: 2}) => x + y;
+}
+
+/// This class uses its type variable.
+class E<T> {
+ var f = () => "f";
+ get g => (T x) => "g($x)";
+ a() => "a";
+ b(T x) => x;
+ c(T x, [T y = 2]) => x + y;
+ d(T x, {T y: 2}) => x + y;
+}
+
+expect(expected, actual) {
+ print("Expecting '$expected' and got '$actual'");
+ if (expected != actual) {
+ print("Expected '$expected' but got '$actual'");
+ throw "Expected '$expected' but got '$actual'";
+ }
+}
+
+test(o) {
+ expect("f", o.f());
+ expect("f", (o.f)());
+ expect("g(42)", o.g(42));
+ expect("g(42)", (o.g)(42));
+ expect("a", o.a());
+ expect("a", (o.a)());
+ expect(42, o.b(42));
+ expect(42, (o.b)(42));
+ expect(42, o.c(40));
+ expect(42, (o.c)(40));
+ expect(87, o.c(80, 7));
+ expect(87, (o.c)(80, 7));
+ expect(42, o.d(40));
+ expect(42, (o.d)(40));
+ expect(87, o.d(80, y: 7));
+ expect(87, (o.d)(80, y: 7));
+}
+
+main(arguments) {
+ test(new C());
+ test(new D<int>());
+ test(new E<int>());
+}

Powered by Google App Engine
This is Rietveld 408576698