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