Skip to content

[analysis_server] Do not offer CreateClass for method invocations on non-prefix targets - #64193

Open
ayushgupta9906 wants to merge 1 commit into
dart-lang:mainfrom
ayushgupta9906:fix-create-class-undefined-member
Open

[analysis_server] Do not offer CreateClass for method invocations on non-prefix targets#64193
ayushgupta9906 wants to merge 1 commit into
dart-lang:mainfrom
ayushgupta9906:fix-create-class-undefined-member

Conversation

@ayushgupta9906

Copy link
Copy Markdown

Summary

Do not offer the Create class quick fix on method invocations where the target is not an import prefix.

In Dart, an invocation of the form target.name() can only be a class instantiation if target is an import prefix (PrefixElement). Previously, when calling an undefined member on a class (e.g. C.m()), target.staticType evaluated to null, causing CreateClass to erroneously offer to create a top-level class m.

Fixes #64192
Work towards #63444

Changes

  • Updated CreateClass.producers in pkg/analysis_server/lib/src/services/correction/dart/create_class.dart to verify that when targetNode == methodName, target must either be null (unqualified invocation) or a PrefixElement. If target != null and not an import prefix, creating a class is rejected.
  • Added unit tests in pkg/analysis_server/test/src/services/correction/fix/create_class_test.dart covering lowercase and uppercase static method invocations, as well as preserving support for undefined target invocations (e.g. Foo.bar()).

@copybara-service

Copy link
Copy Markdown

Thank you for your contribution! This project uses Gerrit for code reviews. Your pull request has automatically been converted into a code review at:

https://dart-review.googlesource.com/c/sdk/+/545180

Please wait for a developer to review your code review at the above link; you can speed up the review if you sign into Gerrit and manually add a reviewer that has recently worked on the relevant code. See CONTRIBUTING.md to learn how to upload changes to Gerrit directly.

Additional commits pushed to this PR will update both the PR and the corresponding Gerrit CL. After the review is complete on the CL, your reviewer will merge the CL (automatically closing this PR).

@copybara-service

Copy link
Copy Markdown

Gerrit CL has been approved, please wait for a reviewer to merge it.

@copybara-service

Copy link
Copy Markdown

Gerrit CL has been approved, please wait for a reviewer to merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid fix offered for undefined member

1 participant