Skip to content
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

Augmentation libraries: Conflict between super constructor and "The augmentation has an 'extends' clause, but an augmentation target already includes an 'extends' clause" and #56224

Open
rrousselGit opened this issue Jul 11, 2024 · 2 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-augmentations Implementation of the augmentations feature P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@rrousselGit
Copy link

Hello!

Consider a macro applied on the following class:

class BaseClass {}

@Macro()
class Example extends BaseClass {}

The macro may want to augment that class with a constructor that uses super.field:

Example(super.field): super.someNamedConstructor();

The issue is twofold:

  • Augmentations cannot generate an extends if one is present:

    augment class Example extends BaseClass {
      Example(super.field): super.someNamedConstructor();
    }

    This will produce The augmentation has an 'extends' clause, but an augmentation target already includes an 'extends' clause

  • If no extends is specified on the augmentation, then the analyzer seems to fail to find the super.namedConstructor and treat super.field as missing. So the following:

    augment class Example {
     Example(super.field): super.someNamedConstructor();
    }

    Will fail with No associated positional super constructor parameter. Try using a normal parameter, or adding more positional parameters to the super

I assume the problem is that super.someNamedConstructor(); should be able to resolve, by looking at the class definition.

@dart-github-bot
Copy link
Collaborator

Summary: Augmenting a class with a constructor that uses super fails due to conflicting extends clauses and the analyzer's inability to resolve super.namedConstructor when no extends is specified in the augmentation. This prevents macros from properly augmenting classes with constructors that utilize inheritance.

@dart-github-bot dart-github-bot added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jul 11, 2024
@lrhn lrhn added feature-augmentations Implementation of the augmentations feature and removed triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. labels Jul 19, 2024
@lrhn
Copy link
Member

lrhn commented Jul 19, 2024

Is a bug. If specified this way, it's a bug in the specification too.

You should be able to add a constructor from scratch. The class it's defined on already has a superclass, even it the current declaration doesn't declare it.

I'd be slighlty more worried about the other direction:

class Example {
  Example(super.field);
}
augment class Example extends BaseClass {}

That one is probably not valid because it's impossible to assign a function signature to the Example constructor declaration.
In the other direction it should work.

@lrhn lrhn added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. and removed area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Jul 19, 2024
@srawlins srawlins added the P2 A bug or feature request we're likely to work on label Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-augmentations Implementation of the augmentations feature P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants