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