Skip to content

Commit 90be80b

Browse files
authored
#3057. Add "diamond" inheritance case to promotion via assignment tests (#3179)
1 parent d817aa2 commit 90be80b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
/// @assertion We say that a variable `x` is promotable via assignment of an
6+
/// expression of type `T` given variable model `VM` if
7+
/// - `VM = VariableModel(declared, promoted, tested, assigned, unassigned,
8+
/// captured)`
9+
/// - and captured is false
10+
/// - and `S` is the current type of `x` in `VM`
11+
/// - and `T <: S` and not `S <: T`
12+
/// - and `T` is a type of interest for `x` in `tested`
13+
///
14+
/// @description Checks static type of a variable after assignment with a
15+
/// supertype of the declared type as type of interest. Test the "diamond"
16+
/// inheritance.
17+
/// @author sgrekhov22@gmail.com
18+
/// @issue 60622
19+
20+
import '../../Utils/static_type_helper.dart';
21+
22+
class A {}
23+
class B extends A {}
24+
class C extends A {}
25+
class D implements B, C {}
26+
27+
void test(Object a, D d){
28+
a as A;
29+
if (a is B || a is C) {}
30+
a = d; // Not promoted: Neither `B` nor `C` is minimal in `{A, B, C}`.
31+
a.expectStaticType<Exactly<A>>();
32+
}
33+
34+
main() {
35+
test(A(), D());
36+
}

0 commit comments

Comments
 (0)