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

Difference in output for DECLARES_INSTANCE_FIELD in extension and extension type #59847

Open
FMorschel opened this issue Jan 6, 2025 · 3 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-ux A user experience or user interface related issue

Comments

@FMorschel
Copy link
Contributor

I was working on https://dart-review.googlesource.com/c/sdk/+/402622 and I got to this code:

extension E on int {
  final int foo = 1, bar = 2;
}

Which has a similar case as:

extension type A(int i) {
  final int foo = 1, bar = 2;
}

But we have different outputs here:

To start, the error on extension type is a CompileTimeErrorCode and the error on extension is a ParserErrorCode. I'm unsure of what is the differentiation between them but I don't see any semantic differentiation here that would make them different.

But the problem I opened this to discuss is actually the following:

image

Why do we get more errors on one than on the other? That doesn't seem coherent to me.

CC @bwilkerson @scheglov @srawlins

@FMorschel FMorschel added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Jan 6, 2025
@bwilkerson
Copy link
Member

A ParserErrorCode is used for errors produced by the parser; a CompileTimeErrorCode is used for errors produced by later stages of the compiler. From a semantic perspective they're both errors and hence there's no interesting difference. Both will prevent code from being compiled.

Yes, the differences in reporting these diagnostics is a bit odd. I suspect that the only reason they're different is because they're being reported in different pieces of code written by different people. There's certainly no inherent reason for the differences.

@FMorschel
Copy link
Contributor Author

Should we keep this open to make the error on extension to trigger for all variables?

@bwilkerson bwilkerson added the type-ux A user experience or user interface related issue label Jan 7, 2025
@bwilkerson
Copy link
Member

Yes, I think triggering on every variable is the better approach because it's also more consistent with what we'd do if each field were declared in a separate declaration.

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. type-ux A user experience or user interface related issue
Projects
None yet
Development

No branches or pull requests

2 participants