Skip to content

CFE: optional super-initializer parameters inherit default values incorrectly #48142

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 Jan 13, 2022 · 2 comments
Closed
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@alexmarkov
Copy link
Contributor

This is a part of #47525.

co19/LanguageFeatures/Super-parameters/semantics_A06_t10 test fails with RuntimeError on the VM because default values of super-parameters are incorrect.

class S {
  int s1;
  int s2;
  S(this.s1, [this.s2 = 42]);
}

class C extends S {
  int i1;
  int i2;
  C(this.i1, super.s1, int x, [super.s2]) : this.i2 = x;
}

Kernel:

  class S extends core::Object {
    field core::int s1;
    field core::int s2;
    constructor •(core::int s1, [core::int s2 = #C1]) → sem::S
      : sem::S::s1 = s1, sem::S::s2 = s2, super core::Object::•()
      ;
  }
  class C extends sem::S {
    field core::int i1;
    field core::int i2;
    constructor •(core::int i1 = #C1, core::int s1, core::int x, [core::int s2 = #C2]) → sem::C
      : sem::C::i1 = i1, sem::C::i2 = x, super sem::S::•(s1, s2)
      ;
  }

  #C1 = 42
  #C2 = null

Here s2 parameter in C should have a default value #C1 (42), but it has a default value #C2 (null). Parameter i1 is not optional, so it shouldn't have a default value at all.

/cc @johnniwinther @chloestefantsova

@alexmarkov alexmarkov added the legacy-area-front-end Legacy: Use area-dart-model instead. label Jan 13, 2022
@alexmarkov
Copy link
Contributor Author

alexmarkov commented Jan 13, 2022

co19/LanguageFeatures/Super-parameters/summary_A04_t01, co19/LanguageFeatures/Super-parameters/summary_A04_t02 and co19/LanguageFeatures/Super-parameters/type_inference_A05_t01 also fail with RuntimeError due to this bug.

@chloestefantsova
Copy link
Contributor

Thanks for spotting that! I'm working on a fix at https://dart-review.googlesource.com/c/sdk/+/228204.

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