-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Closed
Copy link
Labels
area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-flowImplementation of flow analysis in analyzer/cfeImplementation of flow analysis in analyzer/cfe
Description
If switch statement variable is assigned in when
part then no promotion occurs if case scope is shared. Why there is no promotion in test2()
below?
test1(Object? x) {
switch (x) {
case int v when (x = 42) > 0:
x.expectStaticType<Exactly<int>>(); // Ok, promoted
case _:
x.expectStaticType<Exactly<Object?>>();
}
}
test2(Object? x) {
switch (x) {
case int v when (x = 42) > 0:
case int v:
x.expectStaticType<Exactly<Object?>>(); // No promotion
case _:
x.expectStaticType<Exactly<Object?>>();
}
}
T expectStaticType<R extends Exactly<T>>() {
return this;
}
typedef Exactly<T> = T Function(T);
Dart SDK version: 3.9.0-95.0.dev (dev) (Sun May 4 21:03:05 2025 -0700) on "windows_x64"
Metadata
Metadata
Assignees
Labels
area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-flowImplementation of flow analysis in analyzer/cfeImplementation of flow analysis in analyzer/cfe