Skip to content

Wrong name for invalid factory constructor #30999

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

Open
scheglov opened this issue Oct 4, 2017 · 2 comments
Open

Wrong name for invalid factory constructor #30999

scheglov opened this issue Oct 4, 2017 · 2 comments
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. model-error-recovery Error recovery in analyzer/CFE. P3 A lower priority bug or feature request

Comments

@scheglov
Copy link
Contributor

scheglov commented Oct 4, 2017

class A {
  factory B() => null;
}
library;
import self as self;
import "dart:core" as core;

class A extends core::Object {
  static factory B() → self::A
    return null;
}

Looking inside of the generated Kernel Procedure, I see that the name of the factory is set to B, which is incorrect, because if it were A, then the name would have been empty.

image

What I would expect is that an error is reported, and factory B() is parsed as factory A(), and correspondingly factory B.named() as factory A.named().

@peter-ahe-google
Copy link
Contributor

I agree. This isn't ideal. I noticed this when working on e7f26dc.

@jensjoha
Copy link
Contributor

Current behavior for

class A {
  factory B() => null;
  factory B.named() => null;
}

when compiling with pkg/front_end/tool/fasta compile tmp.dart --dump-ir --strong:

Note: strong mode support is preliminary and may not work.
tmp.dart:3:11: Error: 'B.named' isn't a legal method name.
Did you mean 'A.named'?
  factory B.named() => null;
          ^
tmp.dart: Error: Couldn't find constructor 'B'.
tmp.dart: Error: Couldn't find constructor 'B.named'.
library;
import self as self;
import "dart:core" as core;

class A extends core::Object {
  static factory B() → self::A
    return null;
  static factory named() → self::A
    return null;
}
static const field dynamic #errors = const <dynamic>["tmp.dart:3:11: Error: 'B.named' isn't a legal method name.\nDid you mean 'A.named'?\n  factory B.named() => null;\n          ^", "tmp.dart: Error: Couldn't find constructor 'B'.", "tmp.dart: Error: Couldn't find constructor 'B.named'."]/* from null */;

So an error is given and B.named() does seem to be parsed as A.named().

@jensjoha jensjoha added the P2 A bug or feature request we're likely to work on label Jan 10, 2018
@jensjoha jensjoha added P3 A lower priority bug or feature request and removed P2 A bug or feature request we're likely to work on labels Jun 15, 2021
@johnniwinther johnniwinther added model-error-recovery Error recovery in analyzer/CFE. and removed front-end-fasta-recovery labels Apr 1, 2025
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. model-error-recovery Error recovery in analyzer/CFE. P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

4 participants