22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // Tests the behavior described in
6- // https://github.com/dart-lang/language/issues/4127, namely the fact that when
7- // deciding whether an `==` or `!=` comparison is guaranteed to evaluate to
8- // `true` or `false`, flow analysis considers promoted fields to have their base
9- // type rather than their promoted type.
5+ // Tests that the behavior described in
6+ // https://github.com/dart-lang/language/issues/4127 has been fixed. That is,
7+ // when deciding whether an `==` or `!=` comparison is guaranteed to evaluate to
8+ // `true` or `false`, flow analysis considers promoted fields to have their
9+ // promoted type.
1010
11- // This test is here to make sure we don't change the existing behavior by
12- // accident; if/when we fix #4127, this test should be changed accordingly.
11+ // This test acts as a regression test for #4127.
1312
1413import '../static_type_helper.dart' ;
1514
@@ -30,10 +29,10 @@ class C {
3029 y = null ;
3130 }
3231 // In analyzing the `==` check, flow analysis assumes that `_f` has its
33- // unpromoted type (`Object? `), so both branches of the `if` are
34- // reachable. Therefore both `x` and `y` should both be demoted here.
32+ // promoted type (`Null `), so only the `x = null` branch is
33+ // reachable. Therefore only `x` should be demoted here.
3534 x.expectStaticType <Exactly <int ?>>();
36- y.expectStaticType <Exactly <int ? >>();
35+ y.expectStaticType <Exactly <int >>();
3736 }
3837
3938 void testImplicitThisReferenceOnRhsOfEquals () {
@@ -49,10 +48,10 @@ class C {
4948 y = null ;
5049 }
5150 // In analyzing the `==` check, flow analysis assumes that `_f` has its
52- // unpromoted type (`Object? `), so both branches of the `if` are
53- // reachable. Therefore both `x` and `y` should both be demoted here.
51+ // promoted type (`Null `), so only the `x = null` branch is
52+ // reachable. Therefore only `x` should be demoted here.
5453 x.expectStaticType <Exactly <int ?>>();
55- y.expectStaticType <Exactly <int ? >>();
54+ y.expectStaticType <Exactly <int >>();
5655 }
5756
5857 void testImplicitThisReferenceOnLhsOfNotEquals () {
@@ -68,9 +67,9 @@ class C {
6867 y = null ;
6968 }
7069 // In analyzing the `!=` check, flow analysis assumes that `_f` has its
71- // unpromoted type (`Object? `), so both branches of the `if` are
72- // reachable. Therefore both `x` and ` y` should both be demoted here.
73- x.expectStaticType <Exactly <int ? >>();
70+ // promoted type (`Null `), so only the `y = null` branch is
71+ // reachable. Therefore only ` y` should be demoted here.
72+ x.expectStaticType <Exactly <int >>();
7473 y.expectStaticType <Exactly <int ?>>();
7574 }
7675
@@ -87,9 +86,9 @@ class C {
8786 y = null ;
8887 }
8988 // In analyzing the `!=` check, flow analysis assumes that `_f` has its
90- // unpromoted type (`Object? `), so both branches of the `if` are
91- // reachable. Therefore both `x` and ` y` should both be demoted here.
92- x.expectStaticType <Exactly <int ? >>();
89+ // promoted type (`Null `), so only the `y = null` branch is
90+ // reachable. Therefore only ` y` should be demoted here.
91+ x.expectStaticType <Exactly <int >>();
9392 y.expectStaticType <Exactly <int ?>>();
9493 }
9594
@@ -106,10 +105,10 @@ class C {
106105 y = null ;
107106 }
108107 // In analyzing the `==` check, flow analysis assumes that `this._f` has its
109- // unpromoted type (`Object? `), so both branches of the `if` are
110- // reachable. Therefore both `x` and `y` should both be demoted here.
108+ // promoted type (`Null `), so only the `x = null` branch is
109+ // reachable. Therefore only `x` should be demoted here.
111110 x.expectStaticType <Exactly <int ?>>();
112- y.expectStaticType <Exactly <int ? >>();
111+ y.expectStaticType <Exactly <int >>();
113112 }
114113
115114 void testExplicitThisReferenceOnRhsOfEquals () {
@@ -125,10 +124,10 @@ class C {
125124 y = null ;
126125 }
127126 // In analyzing the `==` check, flow analysis assumes that `this._f` has its
128- // unpromoted type (`Object? `), so both branches of the `if` are
129- // reachable. Therefore both `x` and `y` should both be demoted here.
127+ // promoted type (`Null `), so only the `x = null` branch is
128+ // reachable. Therefore only `x` should be demoted here.
130129 x.expectStaticType <Exactly <int ?>>();
131- y.expectStaticType <Exactly <int ? >>();
130+ y.expectStaticType <Exactly <int >>();
132131 }
133132
134133 void testExplicitThisReferenceOnLhsOfNotEquals () {
@@ -144,9 +143,9 @@ class C {
144143 y = null ;
145144 }
146145 // In analyzing the `!=` check, flow analysis assumes that `this._f` has its
147- // unpromoted type (`Object? `), so both branches of the `if` are
148- // reachable. Therefore both `x` and ` y` should both be demoted here.
149- x.expectStaticType <Exactly <int ? >>();
146+ // promoted type (`Null `), so only the `y = null` branch is
147+ // reachable. Therefore only ` y` should be demoted here.
148+ x.expectStaticType <Exactly <int >>();
150149 y.expectStaticType <Exactly <int ?>>();
151150 }
152151
@@ -163,9 +162,9 @@ class C {
163162 y = null ;
164163 }
165164 // In analyzing the `!=` check, flow analysis assumes that `this._f` has its
166- // unpromoted type (`Object? `), so both branches of the `if` are
167- // reachable. Therefore both `x` and ` y` should both be demoted here.
168- x.expectStaticType <Exactly <int ? >>();
165+ // promoted type (`Null `), so only the `y = null` branch is
166+ // reachable. Therefore only ` y` should be demoted here.
167+ x.expectStaticType <Exactly <int >>();
169168 y.expectStaticType <Exactly <int ?>>();
170169 }
171170}
@@ -183,10 +182,10 @@ void testExplicitPropertyReferenceOnLhsOfEquals(C c) {
183182 y = null ;
184183 }
185184 // In analyzing the `==` check, flow analysis assumes that `c._f` has its
186- // unpromoted type (`Object? `), so both branches of the `if` are
187- // reachable. Therefore both `x` and `y` should both be demoted here.
185+ // promoted type (`Null `), so only the `x = null` branch is
186+ // reachable. Therefore only `x` should be demoted here.
188187 x.expectStaticType <Exactly <int ?>>();
189- y.expectStaticType <Exactly <int ? >>();
188+ y.expectStaticType <Exactly <int >>();
190189}
191190
192191void testExplicitPropertyReferenceOnRhsOfEquals (C c) {
@@ -202,10 +201,10 @@ void testExplicitPropertyReferenceOnRhsOfEquals(C c) {
202201 y = null ;
203202 }
204203 // In analyzing the `==` check, flow analysis assumes that `c._f` has its
205- // unpromoted type (`Object? `), so both branches of the `if` are
206- // reachable. Therefore both `x` and `y` should both be demoted here.
204+ // promoted type (`Null `), so only the `x = null` branch is
205+ // reachable. Therefore only `x` should be demoted here.
207206 x.expectStaticType <Exactly <int ?>>();
208- y.expectStaticType <Exactly <int ? >>();
207+ y.expectStaticType <Exactly <int >>();
209208}
210209
211210void testExplicitPropertyReferenceOnLhsOfNotEquals (C c) {
@@ -221,9 +220,9 @@ void testExplicitPropertyReferenceOnLhsOfNotEquals(C c) {
221220 y = null ;
222221 }
223222 // In analyzing the `!=` check, flow analysis assumes that `c._f` has its
224- // unpromoted type (`Object? `), so both branches of the `if` are
225- // reachable. Therefore both `x` and ` y` should both be demoted here.
226- x.expectStaticType <Exactly <int ? >>();
223+ // promoted type (`Null `), so only the `y = null` branch is
224+ // reachable. Therefore only ` y` should be demoted here.
225+ x.expectStaticType <Exactly <int >>();
227226 y.expectStaticType <Exactly <int ?>>();
228227}
229228
@@ -240,9 +239,9 @@ void testExplicitPropertyReferenceOnRhsOfNotEquals(C c) {
240239 y = null ;
241240 }
242241 // In analyzing the `!=` check, flow analysis assumes that `c._f` has its
243- // unpromoted type (`Object? `), so both branches of the `if` are
244- // reachable. Therefore both `x` and ` y` should both be demoted here.
245- x.expectStaticType <Exactly <int ? >>();
242+ // promoted type (`Null `), so only the `y = null` branch is
243+ // reachable. Therefore only ` y` should be demoted here.
244+ x.expectStaticType <Exactly <int >>();
246245 y.expectStaticType <Exactly <int ?>>();
247246}
248247
0 commit comments