Skip to content

[CFE, Patterns] Type of a constant key is not inferred from rhs of the map pattern #51523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexmarkov opened this issue Feb 24, 2023 · 0 comments
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@alexmarkov
Copy link
Contributor

For the following code:

class C<T> {
  const C();
}

void main() {
  var {const C(): a1} = <C<String>, int>{const C<String>(): 1};
}

The type argument of the 1st constant is currently inferred as C<dynamic>, but it should be C<String>.
Kernel:

  static method main() → void {
    dynamic a1;
    {
      final dynamic #0#0 = <bar::C<core::String>, core::int>{#C1: 1};
      if(!(#0#0{core::Map<bar::C<core::String>, core::int>}.{core::Map::length}{core::int} =={core::num::==}{(core::Object) → core::bool} #C2 && #0#0{core::Map<bar::C<core::String>, core::int>}.{core::Map::containsKey}(#C3){(core::Object?) → core::bool} && (let final dynamic #t1 = a1 = #0#0{core::Map<bar::C<core::String>, core::int>}.{core::Map::[]}(#C3){(core::Object?) → dynamic} in true)))
        throw new _in::ReachabilityError::•();
    }
  }


  #C1 = bar::C<core::String> {}
  #C2 = 1
  #C3 = bar::C<dynamic> {}

@munificent kindly provided the following explanation:

We use the matched value's type, Map<C<String>, int> to infer the static type for the map pattern. Then we use the inferred key type from that, C<String> as the context type for the key constant expressions.

co19/LanguageFeatures/Patterns/type_inference_A29_t07 test currently fails with the runtime error because of this bug.

@johnniwinther @chloestefantsova

@alexmarkov alexmarkov added the legacy-area-front-end Legacy: Use area-dart-model instead. label Feb 24, 2023
@chloestefantsova chloestefantsova self-assigned this Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

2 participants