Skip to content

Fix issue 21284: report "no property" error at identifier location - #23755

Open
usefahmed07 wants to merge 4 commits into
dlang:masterfrom
usefahmed07:fix-21284-no-property-error-location
Open

Fix issue 21284: report "no property" error at identifier location#23755
usefahmed07 wants to merge 4 commits into
dlang:masterfrom
usefahmed07:fix-21284-no-property-error-location

Conversation

@usefahmed07

Copy link
Copy Markdown
Contributor

Fixes #21284

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
@usefahmed07
usefahmed07 requested a review from ibuclaw as a code owner August 30, 2026 13:09
@github-actions

github-actions Bot commented Aug 30, 2026

Copy link
Copy Markdown

DMD perf check

Metric Base PR Δ
dmd binary size (stripped) 6.86 MB 6.88 MB +0.17%
All measurements
Metric Base PR Δ
compile hello.d (instr) 214.9 M 214.9 M -0.013%
compile hello.d -O -release (instr) 233.2 M 233.2 M -0.006%
compile Phobos (instr) 5,123.4 M 5,122.7 M -0.014%
compile Phobos codegen (instr) 1,472.5 M 1,472.3 M -0.011%
compile vibe.d (instr) 15,128.8 M 15,123.6 M -0.034%
dmd binary size (stripped) 6.86 MB 6.88 MB +0.17%
hello binary size (stripped) 0.72 MB 0.72 MB 0.00%
peak RSS (compile hello.d) 43.55 MB 43.54 MB -0.03%
peak RSS (compile Phobos) 619.9 MB 619.2 MB -0.13%
peak RSS (compile vibe.d) 1918 MB 1917 MB -0.03%
compile dmd itself (wall) 11.5 s 11.6 s +0.38%
compile hello.d (wall) 59.6 ms 60.0 ms +0.75%
compile Phobos (wall) 1,330 ms 1,336 ms +0.48%

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we compute this from the loc? adding additional fields to the AST consumes more memory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we compute this from the loc? adding additional fields to the AST consumes more memory?

Screenshot From 2026-09-03 20-53-12 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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt that the additional memory consumed by this is worth the mildly better resolution of the error.
Linked PR is not merged.

@usefahmed07

Copy link
Copy Markdown
Contributor Author

@thewilsonator What about this lgtm btw

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.

Wrong location for "no property ... on type ..." error

2 participants