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

Macros: Augmenting a constructor doesn't copy over the default values. #55747

Open
rrousselGit opened this issue May 16, 2024 · 2 comments
Open
Labels
area-fe-analyzer-shared Assigned by engineers; when triaging, prefer either area-front-end or area-analyzer. cfe-feature-augmentation Implement augmentation features in the CFE feature-augmentations Implementation of the augmentations feature

Comments

@rrousselGit
Copy link

rrousselGit commented May 16, 2024

Hello!

Consider the following code:

@override
FutureOr<void> buildDefinitionForClass(ClassDeclaration clazz, TypeDefinitionBuilder builder) async{
  final constructor = await builder.constructorsOf(clazz);

  final builder2 = await builder.buildConstructor(constructor.first.identifier);

  builder2.augment();
}

Then, given:

@Macro()
class DataClass {
  DataClass({this.b = 42});
...
}

This will generate:

augment class DataClass {
  augment DataClass({prefix0.int b, });
}

This generated code will fail, because the augmented constructor lacks a default value.

@lrhn lrhn added the feature-augmentations Implementation of the augmentations feature label May 16, 2024
@lrhn
Copy link
Member

lrhn commented May 16, 2024

That looks like correctly generated augmentations. The augmentation itself should inherit the default value from the declaration it augments (an augmenting function or constructor cannot declare a new default value, only the original declaration can declare the default values, as currently specified).

If the code doesn't work, then it's the augmentation implementation that doesn't do what it should.

@rrousselGit
Copy link
Author

rrousselGit commented May 16, 2024

Interesting. Because at the moment, the augmenting constructor can define default values just fine.

We can generate augment DataClass(int a, {int b = 42}) and have no error.
In fact it seems like the augmentation can specify a default value that's different from the original, and that works too.

@lrhn lrhn added the area-fe-analyzer-shared Assigned by engineers; when triaging, prefer either area-front-end or area-analyzer. label May 19, 2024
@johnniwinther johnniwinther added the cfe-feature-augmentation Implement augmentation features in the CFE label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-fe-analyzer-shared Assigned by engineers; when triaging, prefer either area-front-end or area-analyzer. cfe-feature-augmentation Implement augmentation features in the CFE feature-augmentations Implementation of the augmentations feature
Projects
None yet
Development

No branches or pull requests

3 participants