Bug 17301 – Unhelpful error message on template and non-template struct defined in separate modules
Status
RESOLVED
Resolution
INVALID
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-04-07T09:20:28Z
Last change time
2022-11-18T09:45:21Z
Assigned to
No Owner
Creator
MrSmith33
Comments
Comment #0 by mrsmith33 — 2017-04-07T09:20:28Z
module moduleA;
import moduleB;
void main() {
HashMap!(int) map;
}
struct HashMap {}
module moduleB;
struct HashMap(Key) {}
moduleA.d(6): Error: template instance HashMap!int HashMap is not a template declaration, it is a struct
But, when defined in one module:
void main() {
HashMap!(int) map;
}
struct HashMap {}
struct HashMap(Key) {}
hashmap.d(6): Error: struct hashmap.HashMap(Key) conflicts with struct hashmap.HashMap at hashmap.d(5)
Comment #1 by razvan.nitu1305 — 2022-11-18T09:45:21Z
This bug report is invalid. Lookup is first performed in the module scope and only if the symbol is not found the imports are then searched. In this case, HashMap is defined in moduleA and therefore the compiler picks it up and outputs the appropriate error message. If the symbols are in the same scope, of course an ambiguity is raised. This behavior is according to the spec [1], point 4: "Symbol lookup stops as soon as a matching symbol is found. If two symbols with the same name are found at the same lookup phase, this ambiguity will result in a compilation error.". In this bug report, the symbols are not found in the same lookup phase and according to the rules moduleA.HashMap is found first.
[1] https://dlang.org/spec/module.html#name_lookup