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