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

Side by Side Diff: tests/language_strong/covariant_subtyping_test.dart

Issue 2998873002: fix #30427, casting tearoffs to the wrong type (Closed)
Patch Set: Created 3 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 import 'package:expect/expect.dart'; 4 import 'package:expect/expect.dart';
5 5
6 bool isTypeError(e) => e is TypeError; 6 bool isTypeError(e) => e is TypeError;
7 7
8 class Fields<T> { 8 class Fields<T> {
9 T x; 9 T x;
10 T _y; 10 T _y;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 FnChecks<Object> cObj = cInt; 86 FnChecks<Object> cObj = cInt;
87 Expect.throws(() => cObj.setterForT(), isTypeError); 87 Expect.throws(() => cObj.setterForT(), isTypeError);
88 Expect.throws(() => (cObj.setterForT() as F<Object>), isTypeError); 88 Expect.throws(() => (cObj.setterForT() as F<Object>), isTypeError);
89 FnChecks<dynamic> cDyn = cInt; 89 FnChecks<dynamic> cDyn = cInt;
90 cDyn.setterForT(); // allowed fuzzy arrow 90 cDyn.setterForT(); // allowed fuzzy arrow
91 Expect.throws(() => cDyn.setterForT()('hi'), isTypeError); // dcall throws 91 Expect.throws(() => cDyn.setterForT()('hi'), isTypeError); // dcall throws
92 cInt.setterForT()(42); 92 cInt.setterForT()(42);
93 Expect.equals(cObj.getT(), 42); 93 Expect.equals(cObj.getT(), 42);
94 } 94 }
95 95
96 testTearoffReturningFunctionType() {
97 FnChecks<int> cInt = new FnChecks<int>();
98 FnChecks<Object> cObj = cInt;
99
100 Expect.throws(
101 () => cObj.setterForT, isTypeError, 'unsound tear-off throws at runtime');
102 Expect.equals(cInt.setterForT, cInt.setterForT, 'sound tear-off works');
103 }
104
96 testFieldOfFunctionType() { 105 testFieldOfFunctionType() {
97 FnChecks<Object> c = new FnChecks<String>()..f = (String b) {}; 106 FnChecks<Object> c = new FnChecks<String>()..f = (String b) {};
98 Expect.throws(() { 107 Expect.throws(() {
99 F<Object> f = c.f; 108 F<Object> f = c.f;
100 }, isTypeError); 109 }, isTypeError);
101 Expect.throws(() { 110 Expect.throws(() {
102 Object f = c.f; 111 Object f = c.f;
103 }, isTypeError); 112 }, isTypeError);
104 Expect.throws(() => c.f, isTypeError); 113 Expect.throws(() => c.f, isTypeError);
105 Expect.throws(() => c.f(42), isTypeError); 114 Expect.throws(() => c.f(42), isTypeError);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 Expect.throws(() { 219 Expect.throws(() {
211 f(new Object()); 220 f(new Object());
212 }, isTypeError); 221 }, isTypeError);
213 } 222 }
214 223
215 main() { 224 main() {
216 testField(); 225 testField();
217 testPrivateFields(); 226 testPrivateFields();
218 testClassBounds(); 227 testClassBounds();
219 testReturnOfFunctionType(); 228 testReturnOfFunctionType();
229 testTearoffReturningFunctionType();
220 testFieldOfFunctionType(); 230 testFieldOfFunctionType();
221 testFieldOfGenericFunctionType(); 231 testFieldOfGenericFunctionType();
222 testMixinApplication(); 232 testMixinApplication();
223 testGenericMethodBounds(); 233 testGenericMethodBounds();
224 testCallMethod(); 234 testCallMethod();
225 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698