Bug 20563 – module conflicts with package confusing error message

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-02-06T00:15:16Z
Last change time
2024-12-13T19:07:03Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Steven Schveighoffer
Moved to GitHub: dmd#19664 →

Comments

Comment #0 by schveiguy — 2020-02-06T00:15:16Z
If I declare two packages with the same name accidentally, then the compiler tells me there's an error, but doesn't tell me where the conflict is. In some cases, this might be obvious, but in others it's not For example: ----- foo/package.d module foo; ----- bar/package.d module foo; ----- dmd foo/package.d bar/package.d bar/package.d(1): Error: module foo from file bar/package.d conflicts with package name foo This error is OK, since I realize that bar/package.d shouldn't be foo, and I can correct it. However, if I change the order of compilation: dmd bar/package.d foo/package.d foo/package.d(1): Error: module foo from file foo/package.d conflicts with package name foo This error is super-confusing, because of COURSE I want foo/package.d to be package module foo, how does it conflict with the package foo? The error should specify where the previous definition of module-package foo is. I looked at the code for this, the relevant lines are here: https://github.com/dlang/dmd/blob/ee19c0b5c0465dfe1581111bb20042988a32dfdb/src/dmd/dmodule.d#L1081-L1094 Looking at that code, it is telling me there's an error because the package was already resolved to be a package or a module. If I look through the code, I can't find any place where it's set to a package_, (there is a function resolvePKGUnknown, but it's never called, I'm assuming it may have been called at some point in the past) so I assume that this can only happen with two package modules that are competing for the right one. Note that if I just declare a foo.d with module foo, then I get a similar error: foo.d(1): Error: module foo from file foo.d conflicts with package name foo Again, if it said something like: bar/package.d(1): previously declared here then I can instantly see the problem. We might also want to change the message to clarify it's not conflicting with a package, but a declaration of a package module (which must be true since it's never declared a package_ type).
Comment #1 by robert.schadek — 2024-12-13T19:07:03Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19664 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB