Bug 23152 – Bad diagnostic for variable used as a type

Status
NEW
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-06-01T11:44:24Z
Last change time
2024-12-13T19:23:11Z
Keywords
diagnostic
Assigned to
No Owner
Creator
basile-z
Moved to GitHub: dmd#18109 →

Comments

Comment #0 by b2.temp — 2022-06-01T11:44:24Z
The error for ``` struct S1 {} struct S2 { S1 S1; } ``` is > a7F65CC3F01F0.d:2:16: Error: circular reference to variable `a7F65CC3F01F0.S2.S1` I believe the right error should be > a7F65CC3F01F0.d:2:16: Error: variable `a7F65CC3F01F0.S2.S1` is used as a type A quick verification on run.dlang.io shows that this was the case in the past: --- Up to 2.062 : Failure with output: Error: unrecognized switch '-main' 2.063 to 2.064 : Failure with output: ----- onlineapp.d(2): Error: circular reference to 'onlineapp.S2.S1' onlineapp.d(2): Error: S1 is used as a type ----- 2.065.0: Failure with output: onlineapp.d(2): Error: circular reference to 'onlineapp.S2.S1' 2.066.1 to 2.071.2: Failure with output: ----- onlineapp.d(2): Error: circular reference to 'onlineapp.S2.S1' onlineapp.d(2): Error: S1 is used as a type ----- 2.072.2 to 2.078.3: Failure with output: onlineapp.d(2): Error: circular reference to variable 'onlineapp.S2.S1' Since 2.079.1: Failure with output: onlineapp.d(2): Error: circular reference to variable `onlineapp.S2.S1` --- but since 2.072.2 among the two messages only the less relevant is output
Comment #1 by razvan.nitu1305 — 2022-06-03T13:22:30Z
I, personally, find that the "is used as a type error" is actually misleading in this context. S1 is a type, the problem is that the variable should have a different name. The "circular reference to variable S1" is also annoying, but I think it's closer to the truth since you are actually creating a circular reference. Ideally, the error message should be: "variable name S1 conflicts with struct declaration S1". Also, it seems that: void fun() { S1 S1; } compiles just fine. Which should not.
Comment #2 by ibuclaw — 2022-12-28T02:21:28Z
Looks like https://github.com/dlang/dmd/pull/5588 introduced the loss of "S2 is used as a type" diagnostic. In particular this change switched the result of resolving the identifier from an error expression to an error type (the latter doesn't have a "used as a type" follow-up error). https://github.com/dlang/dmd/pull/5588/files#diff-17f8386682e9c4681f8080c09449e8db528014e83496ce7ed72fc82001fd0883R7455-R7460
Comment #3 by robert.schadek — 2024-12-13T19:23:11Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18109 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB