Skip to content

Parse getter with the same name of the enclosing class #30981

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
scheglov opened this issue Oct 3, 2017 · 8 comments
Closed

Parse getter with the same name of the enclosing class #30981

scheglov opened this issue Oct 3, 2017 · 8 comments
Assignees
Labels
front-end-fasta legacy-area-front-end Legacy: Use area-dart-model instead. P2 A bug or feature request we're likely to work on

Comments

@scheglov
Copy link
Contributor

scheglov commented Oct 3, 2017

class A {
  get A => 0;
}
library;
import self as self;
import "dart:core" as core;

class A extends core::Object {
  constructor •() → void
    : super core::Object::•()
    const core::_ConstantExpressionError::•()._throw(new core::_CompileTimeError::•("file:///test.dart:2:12: Error: Can't return from a constructor.\n  get A => 0;\n           ^"));
}

The produced Kernel does not correspond to the original Dart code.

@scheglov scheglov added the legacy-area-front-end Legacy: Use area-dart-model instead. label Oct 3, 2017
@peter-ahe-google
Copy link
Contributor

Interesting. Fasta doesn't even report an error if I change it to this:

class A {
  get A {
    print("Actually, I'm a getter, not a constructor.");
  }
}

main() {
  new A();
}
library;
import self as self;
import "dart:core" as core;

class A extends core::Object {
  constructor •() → void
    : super core::Object::•() {
    core::print("Actually, I'm a getter, not a constructor.");
  }
}
static method main() → dynamic {
  new self::A::•();
}

@peter-ahe-google
Copy link
Contributor

Let me know if this is blocking you.

@bwilkerson
Copy link
Member

I believe that this fixes the AstBuilder (https://dart-review.googlesource.com/c/sdk/+/25580). I've started looking at kernel, but don't know whether I'll have any success and don't mind having someone else look at it.

@bwilkerson
Copy link
Member

@peter-ahe-google I made some changes (https://dart-review.googlesource.com/c/sdk/+/25600) but there was no change in the test status, which either means that my changes didn't have the intended effect or that there are no tests for this case. Advice would be appreciated.

@jensjoha jensjoha added the P2 A bug or feature request we're likely to work on label Jan 10, 2018
@peter-ahe-google
Copy link
Contributor

@bwilkerson I would add the above examples to pkg/front_end/testcases.

Also, @askeksa-google is working on a similar bug. See #30834 and https://dart-review.googlesource.com/c/sdk/+/34120

@peter-ahe-google
Copy link
Contributor

Also #31299

@askeksa-google
Copy link

After https://dart-review.googlesource.com/c/sdk/+/34120 the code now produces a getter properly, plus a synthetic constructor. Can this issue be closed?

@peter-ahe-google
Copy link
Contributor

I'd be most comfortable closing this bug after we've added a regression test corresponding to the getter from my example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
front-end-fasta legacy-area-front-end Legacy: Use area-dart-model instead. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

5 participants