Bug 15077 – Two structs with the same name could have a nicer error message

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-09-17T02:52:00Z
Last change time
2017-02-15T15:04:29Z
Keywords
diagnostic
Assigned to
nobody
Creator
destructionator

Comments

Comment #0 by destructionator — 2015-09-17T02:52:47Z
Consider a case with two modules that define structs with the same name. If you try to assign variables of the two types to each other, the compiler will say something like: f.d(12): Error: cannot implicitly convert expression (white()) of type Color to Color I mentioned this in a SO answer today: http://stackoverflow.com/questions/32615733/struct-composition-with-mixin-and-templates/32621854#32621854 you can borrow code from there but it is trivial to make another one. Anyway, I propose the compiler error message to get a little smarter. The current behavior is nice in most cases, a fully-qualifed name often makes error messages long and ugly, but if the error message is ever in the form of `cannot convert A to A`, it should print the fully qualified name so it makes sense. So actually do a string comparison when building the message and if(typeA.toChars() == typeB.toChars()) use_fully_qualified_name.
Comment #1 by nick — 2017-02-15T15:04:29Z
Marking as duplicate of a newer bug which has more test cases attached. *** This issue has been marked as a duplicate of issue 9631 ***