| 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 // Verify that the static type of a ??= b is the least upper bound of the | 5 // Verify that the static type of a ??= b is the least upper bound of the |
| 6 // static types of a and b. | 6 // static types of a and b. |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 | 9 |
| 10 // Determine whether the VM is running in checked mode. | 10 // Determine whether the VM is running in checked mode. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 void set a(A value) {} | 60 void set a(A value) {} |
| 61 | 61 |
| 62 B get b => null; | 62 B get b => null; |
| 63 | 63 |
| 64 void set b(B value) {} | 64 void set b(B value) {} |
| 65 } | 65 } |
| 66 | 66 |
| 67 class DerivedClass extends ClassWithInstanceGetters { | 67 class DerivedClass extends ClassWithInstanceGetters { |
| 68 dynamic get a => bad(); | 68 dynamic get a => bad(); |
| 69 | 69 |
| 70 void set a(dynamic value) { bad(); } | 70 void set a(dynamic value) { |
| 71 bad(); |
| 72 } |
| 71 | 73 |
| 72 dynamic get b => bad(); | 74 dynamic get b => bad(); |
| 73 | 75 |
| 74 void set b(dynamic value) { bad(); } | 76 void set b(dynamic value) { |
| 77 bad(); |
| 78 } |
| 75 | 79 |
| 76 void derivedTest() { | 80 void derivedTest() { |
| 77 // The static type of super.v ??= e is the LUB of the static types of | 81 // The static type of super.v ??= e is the LUB of the static types of |
| 78 // super.v and e. | 82 // super.v and e. |
| 79 (super.a ??= new A()).a; //# 01: ok | 83 (super.a ??= new A()).a; //# 01: ok |
| 80 Expect.throws(() => (super.a ??= new A()).b, noMethod); //# 02: static type
warning | 84 Expect.throws(() => (super.a ??= new A()).b, noMethod); //# 02: static type
warning |
| 81 (super.a ??= new B()).a; //# 03: ok | 85 (super.a ??= new B()).a; //# 03: ok |
| 82 (super.a ??= new B()).b; //# 04: static type warning | 86 (super.a ??= new B()).b; //# 04: static type warning |
| 83 if (!checkedMode) { | 87 if (!checkedMode) { |
| 84 (super.b ??= new A()).a; //# 05: ok | 88 (super.b ??= new A()).a; //# 05: ok |
| 85 Expect.throws(() => (super.b ??= new A()).b, noMethod); //# 06: static typ
e warning | 89 Expect.throws(() => (super.b ??= new A()).b, noMethod); //# 06: static typ
e warning |
| 86 | 90 |
| 87 // Exactly the same static warnings that would be caused by super.v = e | 91 // Exactly the same static warnings that would be caused by super.v = e |
| 88 // are also generated in the case of super.v ??= e. | 92 // are also generated in the case of super.v ??= e. |
| 89 super.b ??= new C(); //# 07: static type warning | 93 super.b ??= new C(); //# 07: static type warning |
| 90 } | 94 } |
| 91 } | 95 } |
| 92 } | 96 } |
| 93 | 97 |
| 94 main() { | 98 main() { |
| 95 // Make sure the "none" test fails if "??=" is not implemented. This makes | 99 // Make sure the "none" test fails if "??=" is not implemented. This makes |
| 96 // status files easier to maintain. | 100 // status files easier to maintain. |
| 97 var _; _ ??= null; | 101 var _; |
| 102 _ ??= null; |
| 98 | 103 |
| 99 new DerivedClass().derivedTest(); | 104 new DerivedClass().derivedTest(); |
| 100 | 105 |
| 101 // The static type of v ??= e is the LUB of the static types of v and e. | 106 // The static type of v ??= e is the LUB of the static types of v and e. |
| 102 (a ??= new A()).a; //# 08: ok | 107 (a ??= new A()).a; //# 08: ok |
| 103 Expect.throws(() => (a ??= new A()).b, noMethod); //# 09: static type warning | 108 Expect.throws(() => (a ??= new A()).b, noMethod); //# 09: static type warning |
| 104 (a ??= new B()).a; //# 10: ok | 109 (a ??= new B()).a; //# 10: ok |
| 105 (a ??= new B()).b; //# 11: static type warning | 110 (a ??= new B()).b; //# 11: static type warning |
| 106 if (!checkedMode) { | 111 if (!checkedMode) { |
| 107 (b ??= new A()).a; //# 12: ok | 112 (b ??= new A()).a; //# 12: ok |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 (new ClassWithInstanceGetters()?.a ??= new B()).b; //# 39: static type warning | 170 (new ClassWithInstanceGetters()?.a ??= new B()).b; //# 39: static type warning |
| 166 if (!checkedMode) { | 171 if (!checkedMode) { |
| 167 (new ClassWithInstanceGetters()?.b ??= new A()).a; //# 40: ok | 172 (new ClassWithInstanceGetters()?.b ??= new A()).a; //# 40: ok |
| 168 Expect.throws(() => (new ClassWithInstanceGetters()?.b ??= new A()).b, noMet
hod); //# 41: static type warning | 173 Expect.throws(() => (new ClassWithInstanceGetters()?.b ??= new A()).b, noMet
hod); //# 41: static type warning |
| 169 | 174 |
| 170 // Exactly the same static warnings that would be caused by e1.v ??= e2 are | 175 // Exactly the same static warnings that would be caused by e1.v ??= e2 are |
| 171 // also generated in the case of e1?.v ??= e2. | 176 // also generated in the case of e1?.v ??= e2. |
| 172 new ClassWithInstanceGetters()?.b ??= new C(); //# 42: static type warning | 177 new ClassWithInstanceGetters()?.b ??= new C(); //# 42: static type warning |
| 173 } | 178 } |
| 174 } | 179 } |
| OLD | NEW |