[Issue 20267] New: Error: `string` is used as a type - and similar “ smart” error messages
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Oct 4 21:59:19 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=20267
Issue ID: 20267
Summary: Error: `string` is used as a type - and similar “
smart” error messages
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: minor
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: desisma at heidel.beer
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.
--
More information about the Digitalmars-d-bugs
mailing list