Skip to content

Record pattern promotes fields from void to Object? #60609

Open
@lrhn

Description

@lrhn

Example:

void main() {
  var s = ("a", "b", "c") as (Object?, void, Object?);
  switch (s) {
    case var x when x.l("1.x") || s.l("1.s"): // void
    case var x when x.l("2.x") || s.l("2.s"): // void
    case (_, _, _) && var x when x.l("3.x") || s.l("3.s"): // Object?
    case var x when x.l("4.x") || s.l("4.s"): // Object?
  }
}

extension <T> on T {
  bool l(String name) {
    print("$name: $this:$runtimeType @ $T"); // value, runtime and static type
    return false;
  }
}

The case (_, _, _), which should be a no-op for a matched value type of (Object?, void, Object?)
"promotes" the middle record field's static type to Object?.

That loses void protection.
If it's not an implementation bug, then it's a spec bug, but it should still be fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-patternsImplementation of patterns in analyzer/cfetype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions