OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 | 4 |
5 // Test for locateSingleElement bug. | 5 // Test for locateSingleElement bug. |
6 | 6 |
7 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
8 | 8 |
9 class T { | 9 class T { |
10 foo() => 'T.foo'; // This is the single element. | 10 foo() => 'T.foo'; // This is the single element. |
11 } | 11 } |
12 | 12 |
13 class C implements T { | 13 class C implements T { |
14 // There is a warning that C does not implement 'foo'. | 14 // There is a warning that C does not implement 'foo'. |
15 } | 15 } |
16 | 16 |
17 @NoInline() @AssumeDynamic() | 17 @NoInline() |
18 assumeT(x) { // returns inferred subtype(T). | 18 @AssumeDynamic() |
| 19 assumeT(x) { |
| 20 // returns inferred subtype(T). |
19 if (x is T) return x; | 21 if (x is T) return x; |
20 throw "Not T"; | 22 throw "Not T"; |
21 } | 23 } |
22 | 24 |
23 var log = []; | 25 var log = []; |
24 demo() { | 26 demo() { |
25 log.add(new T()); // T is created. | 27 log.add(new T()); // T is created. |
26 var a = assumeT(new C()); // C is created. | 28 var a = assumeT(new C()); // C is created. |
27 | 29 |
28 // The call "a.foo()" should be a NoSuchMethodError, but a bug in | 30 // The call "a.foo()" should be a NoSuchMethodError, but a bug in |
29 // locateSingleElement used to lead to T.foo being inlined. There is a single | 31 // locateSingleElement used to lead to T.foo being inlined. There is a single |
30 // method. T.foo, that matches subtype(T), but it should be rejected because | 32 // method. T.foo, that matches subtype(T), but it should be rejected because |
31 // not all instantiated classes that are subtype(T) have that method. | 33 // not all instantiated classes that are subtype(T) have that method. |
32 log.add(a.foo()); | 34 log.add(a.foo()); |
33 } | 35 } |
34 | 36 |
35 main() { | 37 main() { |
36 Expect.throws(demo); | 38 Expect.throws(demo); |
37 } | 39 } |
OLD | NEW |