Bug 20267 – Error: `string` is used as a type - and similar “smart” error messages

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-10-04T21:59:19Z
Last change time
2019-10-07T22:57:22Z
Keywords
pull
Assigned to
No Owner
Creator
Elias Batek (0xEAB)

Comments

Comment #0 by desisma — 2019-10-04T21:59:19Z
There are just a handful of types that are actual keywords. One of the most famous examples for the opposite case is probably `string` - that is just an alias defined in `object.d`. So what could go wrong? Let's assume (this did actually happen to me) one accidentally forgets the variable name in such a statement: immutable int i = 0; --> results in immutable int = 0; Luckily, the compiler's going to tell us that there's something wrong: "Error: no identifier for declarator `int`". Now let's say, this happens to a non-keyword type. immutable string = "foo"; ...is perfectly fine. We've declared a variable named `string` of type `immutable(immutable(char)[])`. The "evil" thing is what happens when one would actually try to use the type whose name got "overridden" by the variable. One will end up with the following "love letter" from the compiler: "Error: `string` is used as a type". And one will be confused - especially when this happens because one accidentally "didn't" name a variable. The good news is: this is rather trivial to fix. And my PR is just a change to the testsuite away.
Comment #1 by dlang-bot — 2019-10-04T22:16:17Z
@0xEAB created dlang/dmd pull request #10450 "Fix issue 20267 - Error: `string` is used as a type - and similar “ smart” error messages" fixing this issue: - Fix issue 20267 - var used as a type error messages https://github.com/dlang/dmd/pull/10450
Comment #2 by dlang-bot — 2019-10-07T22:57:22Z
dlang/dmd pull request #10450 "Fix issue 20267 - Error: `string` is used as a type - and similar “smart” error messages" was merged into master: - 6ebafdcbddca5c6cb01082f062cf68e2bcf3c8c3 by 0xEAB: Fix issue 20267 - var used as a type error messages https://github.com/dlang/dmd/pull/10450