Skip to content

analyzer: update dot shorthand diagnostic to mention static scope#62954

Open
console-log-life wants to merge 2 commits intodart-lang:mainfrom
console-log-life:main
Open

analyzer: update dot shorthand diagnostic to mention static scope#62954
console-log-life wants to merge 2 commits intodart-lang:mainfrom
console-log-life:main

Conversation

@console-log-life
Copy link
Copy Markdown

Summary

This PR improves the diagnostic message for dot shorthand expressions in the analyzer. The goal is to address the misleading "no context type" message as discussed in #62863.

The Problem

Previously, when a dot shorthand was used with types like dynamic, void, or certain Record types, the analyzer reported:

"A dot shorthand can't be used where there is no context type."

As pointed out by the team, this is inaccurate. A context type (like dynamic) does exist, but it is a type that lacks a static scope, which is required for the dot shorthand to resolve members.

Changes Made

  • Updated pkg/analyzer/messages.yaml: Changed the problemMessage for dotShorthandMissingContext to accurately reflect the "static scope" requirement.
  • Improved Documentation: Revised the Description and Example sections in the YAML file to explain that the issue isn't just a missing type, but a type that doesn't support static member lookup.
  • Enhanced Common Fixes: Added clearer guidance on how to fix the error by providing a context type with a static scope (like a Class or Enum).
  • Formatting: Carefully maintained YAML indentation and used backticks for code references to ensure the PR meets SDK contribution standards.

Verification

This change correctly covers the edge cases where a context type is present but lacks static scope:

  • fd(.hash) where context is dynamic.
  • fv(.hash) where context is void.
  • fr(.hash) where context is a Record.

Fixes #62863

…e types

Updated the diagnostic message for dot shorthand in messages.yaml. 
The previous message "no context type" was misleading when the context type was 'dynamic', 'void', or a Record type.

The new message correctly identifies that these types lack a static scope. Updated the documentation and common fixes accordingly.

Fixes dart-lang#62863
…e types

Updated the diagnostic message for dot shorthand in messages.yaml. 
The previous message "no context type" was misleading when the context type was 'dynamic', 'void', or a Record type.

The new message correctly identifies that these types lack a static scope. Updated the documentation and common fixes accordingly.

Fixes dart-lang#62863
@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/+/489900

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

CL has new comments, please view and respond to them in Gerrit.

If a reviewer requested changes, push new commits to this PR and it will be automatically copied to Gerrit. After that you can mark reviewer comments as resolved in Gerrit and request another round of reviews.

Note: when you add comments in Gerrit they only become visible after you send them by clicking Reply and Send.

@bwilkerson
Copy link
Copy Markdown
Member

Please see the feedback on the Gerrit CL at https://dart-review.googlesource.com/c/sdk/+/489900.

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.

Analyzer misleading message for dot-shorthand on non-scope-type

2 participants