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

Improve diagnostic situation for constructor tearoffs from deferred library #54611

Open
parlough opened this issue Jan 12, 2024 · 0 comments
Open
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-messages Poor/undesirable messaging in errors/warnings emitted by the CFE.

Comments

@parlough
Copy link
Member

parlough commented Jan 12, 2024

Consider:

other.dart:

class C {}

main.dart:

import 'other.dart' deferred as other;

void main() {
  test(other.C.new);
}

void test(Object Function() f) {
  print(f);
}

This provides no analyzer diagnostics (which is a known issue that applies to more situations), but the front end does error:

main.dart:4:16:
Error: 'new' can only be used as a constructor reference.
  test(other.C.new);
               ^^^
Error: Compilation failed.

Most deferred errors will happen at runtime if you haven't imported the library with an explanation as to why, but this is happening at compile time, I'm assuming because the tear off is constant?

It's nice for it to happen at compile time, but the error isn't helpful for developers trying to resolve it since .new is a constructor reference.

Side note: I discovered this issue since unnecessary_lambdas made this change automatically (fix here).

@parlough parlough added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label Jan 12, 2024
@johnniwinther johnniwinther added the cfe-messages Poor/undesirable messaging in errors/warnings emitted by the CFE. label Jan 15, 2024
copybara-service bot pushed a commit that referenced this issue Jan 16, 2024
I didn't add this exception to the documentation as it's pretty niche and I'm afraid it might detract from the goal of the lint. Happy to add something if you think it's worth while though :)

Bug reference: #54611

Change-Id: I977be945208aee285f7bb44f73f7953b0646dc14
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/346100
Commit-Queue: Phil Quitslund <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
Auto-Submit: Parker Lougheed <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-messages Poor/undesirable messaging in errors/warnings emitted by the CFE.
Projects
None yet
Development

No branches or pull requests

2 participants