| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 void set a(A value) { bad(); } | 67 void set a(A value) { bad(); } |
| 68 | 68 |
| 69 B get b => bad(); | 69 B get b => bad(); |
| 70 | 70 |
| 71 void set b(B value) { bad(); } | 71 void set b(B value) { bad(); } |
| 72 | 72 |
| 73 void derivedTest() { | 73 void derivedTest() { |
| 74 // The static type of super.v ??= e is the LUB of the static types of | 74 // The static type of super.v ??= e is the LUB of the static types of |
| 75 // super.v and e. | 75 // super.v and e. |
| 76 (super.a ??= new A()).a; /// 01: ok | 76 (super.a ??= new A()).a; //# 01: ok |
| 77 Expect.throws(() => (super.a ??= new A()).b, noMethod); /// 02: static type
warning | 77 Expect.throws(() => (super.a ??= new A()).b, noMethod); //# 02: static type
warning |
| 78 (super.a ??= new B()).a; /// 03: ok | 78 (super.a ??= new B()).a; //# 03: ok |
| 79 (super.a ??= new B()).b; /// 04: static type warning | 79 (super.a ??= new B()).b; //# 04: static type warning |
| 80 if (!checkedMode) { | 80 if (!checkedMode) { |
| 81 (super.b ??= new A()).a; /// 05: ok | 81 (super.b ??= new A()).a; //# 05: ok |
| 82 Expect.throws(() => (super.b ??= new A()).b, noMethod); /// 06: static typ
e warning | 82 Expect.throws(() => (super.b ??= new A()).b, noMethod); //# 06: static typ
e warning |
| 83 | 83 |
| 84 // Exactly the same static warnings that would be caused by super.v = e | 84 // Exactly the same static warnings that would be caused by super.v = e |
| 85 // are also generated in the case of super.v ??= e. | 85 // are also generated in the case of super.v ??= e. |
| 86 super.b ??= new C(); /// 07: static type warning | 86 super.b ??= new C(); //# 07: static type warning |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 main() { | 91 main() { |
| 92 // Make sure the "none" test fails if "??=" is not implemented. This makes | 92 // Make sure the "none" test fails if "??=" is not implemented. This makes |
| 93 // status files easier to maintain. | 93 // status files easier to maintain. |
| 94 var _; _ ??= null; | 94 var _; _ ??= null; |
| 95 | 95 |
| 96 new DerivedClass().derivedTest(); | 96 new DerivedClass().derivedTest(); |
| 97 | 97 |
| 98 // The static type of v ??= e is the LUB of the static types of v and e. | 98 // The static type of v ??= e is the LUB of the static types of v and e. |
| 99 (a ??= new A()).a; /// 08: ok | 99 (a ??= new A()).a; //# 08: ok |
| 100 Expect.throws(() => (a ??= new A()).b, noMethod); /// 09: static type warning | 100 Expect.throws(() => (a ??= new A()).b, noMethod); //# 09: static type warning |
| 101 (a ??= new B()).a; /// 10: ok | 101 (a ??= new B()).a; //# 10: ok |
| 102 (a ??= new B()).b; /// 11: static type warning | 102 (a ??= new B()).b; //# 11: static type warning |
| 103 if (!checkedMode) { | 103 if (!checkedMode) { |
| 104 (b ??= new A()).a; /// 12: ok | 104 (b ??= new A()).a; //# 12: ok |
| 105 Expect.throws(() => (b ??= new A()).b, noMethod); /// 13: static type warnin
g | 105 Expect.throws(() => (b ??= new A()).b, noMethod); //# 13: static type warnin
g |
| 106 | 106 |
| 107 // Exactly the same static warnings that would be caused by v = e are also | 107 // Exactly the same static warnings that would be caused by v = e are also |
| 108 // generated in the case of v ??= e. | 108 // generated in the case of v ??= e. |
| 109 b ??= new C(); /// 14: static type warning | 109 b ??= new C(); //# 14: static type warning |
| 110 } | 110 } |
| 111 | 111 |
| 112 // The static type of C.v ??= e is the LUB of the static types of C.v and e. | 112 // The static type of C.v ??= e is the LUB of the static types of C.v and e. |
| 113 (ClassWithStaticGetters.a ??= new A()).a; /// 15: ok | 113 (ClassWithStaticGetters.a ??= new A()).a; //# 15: ok |
| 114 Expect.throws(() => (ClassWithStaticGetters.a ??= new A()).b, noMethod); /// 1
6: static type warning | 114 Expect.throws(() => (ClassWithStaticGetters.a ??= new A()).b, noMethod); //# 1
6: static type warning |
| 115 (ClassWithStaticGetters.a ??= new B()).a; /// 17: ok | 115 (ClassWithStaticGetters.a ??= new B()).a; //# 17: ok |
| 116 (ClassWithStaticGetters.a ??= new B()).b; /// 18: static type warning | 116 (ClassWithStaticGetters.a ??= new B()).b; //# 18: static type warning |
| 117 if (!checkedMode) { | 117 if (!checkedMode) { |
| 118 (ClassWithStaticGetters.b ??= new A()).a; /// 19: ok | 118 (ClassWithStaticGetters.b ??= new A()).a; //# 19: ok |
| 119 Expect.throws(() => (ClassWithStaticGetters.b ??= new A()).b, noMethod); ///
20: static type warning | 119 Expect.throws(() => (ClassWithStaticGetters.b ??= new A()).b, noMethod); //#
20: static type warning |
| 120 | 120 |
| 121 // Exactly the same static warnings that would be caused by C.v = e are | 121 // Exactly the same static warnings that would be caused by C.v = e are |
| 122 // also generated in the case of C.v ??= e. | 122 // also generated in the case of C.v ??= e. |
| 123 ClassWithStaticGetters.b ??= new C(); /// 21: static type warning | 123 ClassWithStaticGetters.b ??= new C(); //# 21: static type warning |
| 124 } | 124 } |
| 125 | 125 |
| 126 // The static type of e1.v ??= e2 is the LUB of the static types of e1.v and | 126 // The static type of e1.v ??= e2 is the LUB of the static types of e1.v and |
| 127 // e2. | 127 // e2. |
| 128 (new ClassWithInstanceGetters().a ??= new A()).a; /// 22: ok | 128 (new ClassWithInstanceGetters().a ??= new A()).a; //# 22: ok |
| 129 Expect.throws(() => (new ClassWithInstanceGetters().a ??= new A()).b, noMethod
); /// 23: static type warning | 129 Expect.throws(() => (new ClassWithInstanceGetters().a ??= new A()).b, noMethod
); //# 23: static type warning |
| 130 (new ClassWithInstanceGetters().a ??= new B()).a; /// 24: ok | 130 (new ClassWithInstanceGetters().a ??= new B()).a; //# 24: ok |
| 131 (new ClassWithInstanceGetters().a ??= new B()).b; /// 25: static type warning | 131 (new ClassWithInstanceGetters().a ??= new B()).b; //# 25: static type warning |
| 132 if (!checkedMode) { | 132 if (!checkedMode) { |
| 133 (new ClassWithInstanceGetters().b ??= new A()).a; /// 26: ok | 133 (new ClassWithInstanceGetters().b ??= new A()).a; //# 26: ok |
| 134 Expect.throws(() => (new ClassWithInstanceGetters().b ??= new A()).b, noMeth
od); /// 27: static type warning | 134 Expect.throws(() => (new ClassWithInstanceGetters().b ??= new A()).b, noMeth
od); //# 27: static type warning |
| 135 | 135 |
| 136 // Exactly the same static warnings that would be caused by e1.v = e2 are | 136 // Exactly the same static warnings that would be caused by e1.v = e2 are |
| 137 // also generated in the case of e1.v ??= e2. | 137 // also generated in the case of e1.v ??= e2. |
| 138 new ClassWithInstanceGetters().b ??= new C(); /// 28: static type warning | 138 new ClassWithInstanceGetters().b ??= new C(); //# 28: static type warning |
| 139 } | 139 } |
| 140 | 140 |
| 141 // The static type of e1[e2] ??= e3 is the LUB of the static types of e1[e2] | 141 // The static type of e1[e2] ??= e3 is the LUB of the static types of e1[e2] |
| 142 // and e3. | 142 // and e3. |
| 143 ((<A>[null])[0] ??= new A()).a; /// 29: ok | 143 ((<A>[null])[0] ??= new A()).a; //# 29: ok |
| 144 Expect.throws(() => ((<A>[null])[0] ??= new A()).b, noMethod); /// 30: static
type warning | 144 Expect.throws(() => ((<A>[null])[0] ??= new A()).b, noMethod); //# 30: static
type warning |
| 145 ((<A>[null])[0] ??= new B()).a; /// 31: ok | 145 ((<A>[null])[0] ??= new B()).a; //# 31: ok |
| 146 ((<A>[null])[0] ??= new B()).b; /// 32: static type warning | 146 ((<A>[null])[0] ??= new B()).b; //# 32: static type warning |
| 147 if (!checkedMode) { | 147 if (!checkedMode) { |
| 148 ((<B>[null])[0] ??= new A()).a; /// 33: ok | 148 ((<B>[null])[0] ??= new A()).a; //# 33: ok |
| 149 Expect.throws(() => ((<B>[null])[0] ??= new A()).b, noMethod); /// 34: stati
c type warning | 149 Expect.throws(() => ((<B>[null])[0] ??= new A()).b, noMethod); //# 34: stati
c type warning |
| 150 | 150 |
| 151 // Exactly the same static warnings that would be caused by e1[e2] = e3 are | 151 // Exactly the same static warnings that would be caused by e1[e2] = e3 are |
| 152 // also generated in the case of e1[e2] ??= e3. | 152 // also generated in the case of e1[e2] ??= e3. |
| 153 (<B>[null])[0] ??= new C(); /// 35: static type warning | 153 (<B>[null])[0] ??= new C(); //# 35: static type warning |
| 154 } | 154 } |
| 155 | 155 |
| 156 // The static type of e1?.v op= e2 is the static type of e1.v op e2, | 156 // The static type of e1?.v op= e2 is the static type of e1.v op e2, |
| 157 // therefore the static type of e1?.v ??= e2 is the static type of | 157 // therefore the static type of e1?.v ??= e2 is the static type of |
| 158 // e1.v ?? e2, which is the LUB of the static types of e1?.v and e2. | 158 // e1.v ?? e2, which is the LUB of the static types of e1?.v and e2. |
| 159 (new ClassWithInstanceGetters()?.a ??= new A()).a; /// 36: ok | 159 (new ClassWithInstanceGetters()?.a ??= new A()).a; //# 36: ok |
| 160 Expect.throws(() => (new ClassWithInstanceGetters()?.a ??= new A()).b, noMetho
d); /// 37: static type warning | 160 Expect.throws(() => (new ClassWithInstanceGetters()?.a ??= new A()).b, noMetho
d); //# 37: static type warning |
| 161 (new ClassWithInstanceGetters()?.a ??= new B()).a; /// 38: ok | 161 (new ClassWithInstanceGetters()?.a ??= new B()).a; //# 38: ok |
| 162 (new ClassWithInstanceGetters()?.a ??= new B()).b; /// 39: static type warning | 162 (new ClassWithInstanceGetters()?.a ??= new B()).b; //# 39: static type warning |
| 163 if (!checkedMode) { | 163 if (!checkedMode) { |
| 164 (new ClassWithInstanceGetters()?.b ??= new A()).a; /// 40: ok | 164 (new ClassWithInstanceGetters()?.b ??= new A()).a; //# 40: ok |
| 165 Expect.throws(() => (new ClassWithInstanceGetters()?.b ??= new A()).b, noMet
hod); /// 41: static type warning | 165 Expect.throws(() => (new ClassWithInstanceGetters()?.b ??= new A()).b, noMet
hod); //# 41: static type warning |
| 166 | 166 |
| 167 // Exactly the same static warnings that would be caused by e1.v ??= e2 are | 167 // Exactly the same static warnings that would be caused by e1.v ??= e2 are |
| 168 // also generated in the case of e1?.v ??= e2. | 168 // also generated in the case of e1?.v ??= e2. |
| 169 new ClassWithInstanceGetters()?.b ??= new C(); /// 42: static type warning | 169 new ClassWithInstanceGetters()?.b ??= new C(); //# 42: static type warning |
| 170 } | 170 } |
| 171 } | 171 } |
| OLD | NEW |