Bug 21062 – Confusing error when using a keyword as an identifier for a declaration

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-07-21T07:13:06Z
Last change time
2022-11-08T14:36:51Z
Keywords
diagnostic, pull, trivial
Assigned to
No Owner
Creator
Andrej Mitrovic

Comments

Comment #0 by andrej.mitrovich — 2020-07-21T07:13:06Z
DMD 2.093 (also tested with 2.089) This is OK: ----- struct S { public time_t time; public bool synced; } ----- $ dmd -c test.d > test.d(9,19): Error: undefined identifier `time_t`, did you mean variable `time`? But look at this: ----- struct S { public time_t time; public bool synchronized; } ----- $ dmd -c test.d > test.d(4): Error: no identifier for declarator bool > test.d(4): Error: declaration expected following attribute, not ; There is no mention of `time_t` being undefined.
Comment #1 by andrej.mitrovich — 2020-07-21T07:15:07Z
So apparently I forgot synchronized is a statement, but the compiler should emit a better diagnostic. I'll rename the issue.
Comment #2 by b2.temp — 2020-07-21T07:18:14Z
yeah it's a keyword, so parser error. Maybe just "cannot use `%s` as identifier because this is a keyword" and as errorSupplemental() "append a trailing underscore"
Comment #3 by dlang-bot — 2022-11-06T17:16:50Z
@dkorpel created dlang/dmd pull request #14627 "Fix 21062 - Confusing error when using a keyword as an identifier for…" fixing this issue: - Fix 21062 - Confusing error when using a keyword as an identifier for a declaration https://github.com/dlang/dmd/pull/14627
Comment #4 by dlang-bot — 2022-11-08T14:36:51Z
dlang/dmd pull request #14627 "Fix 21062 - Confusing error when using a keyword as an identifier for…" was merged into master: - d124ecbb53869d6902e5140becca920c80f9555d by Dennis Korpel: Fix 21062 - Confusing error when using a keyword as an identifier for a declaration https://github.com/dlang/dmd/pull/14627