Fix issue 21284: report "no property" error at identifier location - #23755
Open
usefahmed07 wants to merge 4 commits into
Open
Fix issue 21284: report "no property" error at identifier location#23755usefahmed07 wants to merge 4 commits into
usefahmed07 wants to merge 4 commits into
Conversation
The "no property `X` for type `Y`" error for enum member access was
reported at the location of the enum type expression instead of the
invalid identifier, e.g. across:
auto x =
E
.
three;
it reported the error on the "E" line instead of the "three" line.
- Add identLoc to DotIdExp, set by the parser from the identifier's
own token location.
- Thread identLoc through dotExp() and use it (falling back to the
previous location when unset) when reporting the "no property"
error for TypeEnum.
- Add fail_compilation test diag21284.d.
Based on the diagnosis and approach explored in dlang#22740 by
Jay-Lokhande.
Fixes https://issues.dlang.org/show_bug.cgi?id=21284
DMD perf check
All measurements
d597dba vs merge-base 078e406 · about these metrics |
| bool noderef; // true if the result of the expression will never be dereferenced | ||
| bool wantsym; // do not replace Symbol with its initializer during semantic() | ||
| bool arrow; // ImportC: if -> instead of . | ||
| Loc identLoc; // location of `ident` itself (may differ from `loc`, e.g. across multiple lines) |
Contributor
There was a problem hiding this comment.
Can we compute this from the loc? adding additional fields to the AST consumes more memory?
Contributor
Author
There was a problem hiding this comment.
Can we compute this from the
loc? adding additional fields to the AST consumes more memory?
Checked - `Loc` is just a 4-byte index, so this only adds ~5 bytes per `DotIdExp` (43→48, measured). It also can't be derived from `loc` alone since the dot-to-identifier gap varies (multi-line chains, comments). #22740 took the same approach, so I think this is fine.
Do you have a suggestion to reduce it?
Contributor
There was a problem hiding this comment.
I doubt that the additional memory consumed by this is worth the mildly better resolution of the error.
Linked PR is not merged.
Contributor
Author
|
@thewilsonator What about this lgtm btw |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21284