Skip to content

Change flow anaylsis to only promote to proper subtypes #4368

@stereotype441

Description

@stereotype441

Flow analysis currently has the rule that type promotion only occurs when the type being tested is a subtype of the previously promoted type. This can lead to counterintuitive behaviors when the type being tested and the previously promoted type are mutual subtypes (see comment from @eernstg and comment from @lrhn on dart-lang/sdk#60609).

In the discussion on that issue, the three of us agreed that it would be better to change the rule so that type promotion only occurs when the type being tested is a proper subtype of the previously promoted type. For example, this would mean that a type that has been promoted to List<Object?> cannot be further promoted to List<dynamic> or List<void>, because these three types are all mutual subtypes.

I'm filing this as a separate issue to distinguish it from dart-lang/sdk#60609, which is primarily caused by a bug in the handling of switches (dart-lang/sdk#60496).

Metadata

Metadata

Assignees

Labels

flow-analysisDiscussions about possible future improvements to flow analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions