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 // SharedOptions=--enable-null-aware-operators | 8 // SharedOptions=--enable-null-aware-operators |
9 | 9 |
10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 ((<A>[null])[0] ??= new B()).a; /// 31: ok | 150 ((<A>[null])[0] ??= new B()).a; /// 31: ok |
151 ((<A>[null])[0] ??= new B()).b; /// 32: static type warning | 151 ((<A>[null])[0] ??= new B()).b; /// 32: static type warning |
152 if (!checkedMode) { | 152 if (!checkedMode) { |
153 ((<B>[null])[0] ??= new A()).a; /// 33: ok | 153 ((<B>[null])[0] ??= new A()).a; /// 33: ok |
154 Expect.throws(() => ((<B>[null])[0] ??= new A()).b, noMethod); /// 34: stati
c type warning | 154 Expect.throws(() => ((<B>[null])[0] ??= new A()).b, noMethod); /// 34: stati
c type warning |
155 | 155 |
156 // Exactly the same static warnings that would be caused by e1[e2] = e3 are | 156 // Exactly the same static warnings that would be caused by e1[e2] = e3 are |
157 // also generated in the case of e1[e2] ??= e3. | 157 // also generated in the case of e1[e2] ??= e3. |
158 (<B>[null])[0] ??= new C(); /// 35: static type warning | 158 (<B>[null])[0] ??= new C(); /// 35: static type warning |
159 } | 159 } |
| 160 |
| 161 // The static type of e1?.v op= e2 is the static type of e1.v op e2, |
| 162 // therefore the static type of e1?.v ??= e2 is the static type of |
| 163 // e1.v ?? e2, which is the LUB of the static types of e1?.v and e2. |
| 164 (new ClassWithInstanceGetters()?.a ??= new A()).a; /// 36: ok |
| 165 Expect.throws(() => (new ClassWithInstanceGetters()?.a ??= new A()).b, noMetho
d); /// 37: static type warning |
| 166 (new ClassWithInstanceGetters()?.a ??= new B()).a; /// 38: ok |
| 167 (new ClassWithInstanceGetters()?.a ??= new B()).b; /// 39: static type warning |
| 168 if (!checkedMode) { |
| 169 (new ClassWithInstanceGetters()?.b ??= new A()).a; /// 40: ok |
| 170 Expect.throws(() => (new ClassWithInstanceGetters()?.b ??= new A()).b, noMet
hod); /// 41: static type warning |
| 171 |
| 172 // Exactly the same static warnings that would be caused by e1.v ??= e2 are |
| 173 // also generated in the case of e1?.v ??= e2. |
| 174 new ClassWithInstanceGetters()?.b ??= new C(); /// 42: static type warning |
| 175 } |
160 } | 176 } |
OLD | NEW |