D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21062 - Confusing error when using a keyword as an identifier for a declaration
Summary: Confusing error when using a keyword as an identifier for a declaration
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: diagnostic, pull, trivial
Depends on:
Blocks:
 
Reported: 2020-07-21 07:13 UTC by Andrej Mitrovic
Modified: 2022-11-08 14:36 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2020-07-21 07:13:06 UTC
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 Andrej Mitrovic 2020-07-21 07:15:07 UTC
So apparently I forgot synchronized is a statement, but the compiler should emit a better diagnostic. I'll rename the issue.
Comment 2 basile-z 2020-07-21 07:18:14 UTC
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 Dlang Bot 2022-11-06 17:16:50 UTC
@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 Dlang Bot 2022-11-08 14:36:51 UTC
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