[Issue 20563] New: module conflicts with package confusing error message
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Feb 6 00:15:16 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20563
Issue ID: 20563
Summary: module conflicts with package confusing error message
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: diagnostic
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: schveiguy at yahoo.com
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).
--
More information about the Digitalmars-d-bugs
mailing list