Skip to content

CFE sometimes fails to promote to non-nullable based on null checks in guards #52241

Description

@stereotype441

When running under the VM, the following constructs fail to promote:

var _ = switch (...) {
  int? y when y != null => ... // `y` is not promoted here
  ...
};
if (... case int? y when y != null) {
  // `y` is not promoted here
}
var _ = [if (... case int? y when y != null) ... // `y` is not promoted here
    ]; // And similar for sets and maps

However, trying to do the same thing with a switch statement does promote:

switch (...) {
  case int? y when y != null:
    // `y` is promoted to `int` here
}

This doesn't happen when running the CFE by itself (e.g. when testing in cfe-strong-linux mode). But it does happen if the program is run under the VM.

The analyzer properly promotes in all these circumstances.

I'm working on a fix.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions