OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Regression test for dart2js: we incorrectly modeled `super.x = rhs` as a | 5 // Regression test for dart2js: we incorrectly modeled `super.x = rhs` as a |
6 // call and not an assignment, so the type of the expression was incorrectly | 6 // call and not an assignment, so the type of the expression was incorrectly |
7 // assumed to be the return type of the setter rather than the type of the rhs. | 7 // assumed to be the return type of the setter rather than the type of the rhs. |
8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
9 | 9 |
10 abstract class A { | 10 abstract class A { |
11 set x(v) {} | 11 set x(v) {} |
12 set z(v) {} | 12 set z(v) {} |
13 set y(v) { return 'hi';} | 13 set y(v) { return 'hi';} |
14 } | 14 } |
15 | 15 |
16 class S extends A { | 16 class S extends A { |
17 var _x; // was bad: inferred as null, than [null | int] | 17 var _x; // was bad: inferred as null, than [null | int] |
18 var _y = ''; // was bad: inferred as String, rather than [String | int] | 18 var _y = ''; // was bad: inferred as String, rather than [String | int] |
19 var _z; // was ok : inferred as [null | int] | 19 var _z; // was ok : inferred as [null | int] |
20 | 20 |
21 set x(v) { | 21 set x(v) { |
22 _x = super.x = v; | 22 _x = super.x = v; |
23 } | 23 } |
24 | 24 |
25 set z(v) { | 25 set z(v) { |
26 super.z = v; | 26 super.z = v; |
27 _z = v; | 27 _z = v; |
28 } | 28 } |
29 | 29 |
30 set y(v) { | 30 set y(v) { |
31 _y = super.y = v; | 31 _y = super.y = v; |
32 } | 32 } |
33 | 33 |
34 get isXNull => _x == null; | 34 get isXNull => _x == null; |
35 get isZNull => _z == null; | 35 get isZNull => _z == null; |
36 } | 36 } |
37 | 37 |
38 main() { | 38 main() { |
39 var s = new S() | 39 var s = new S() |
40 ..x = 2 | 40 ..x = 2 |
41 ..y = 2 | 41 ..y = 2 |
42 ..z = 2; | 42 ..z = 2; |
43 Expect.equals(false, s.isXNull); // was incorrectly optimized to 'true' | 43 Expect.equals(false, s.isXNull); // was incorrectly optimized to 'true' |
44 Expect.equals(false, s._y is String); // was incorrectly optimized to 'true' | 44 Expect.equals(false, s._y is String); // was incorrectly optimized to 'true' |
45 Expect.equals(false, s.isZNull); // prints false | 45 Expect.equals(false, s.isZNull); // prints false |
46 } | 46 } |
OLD | NEW |