Bug 3979 – Order-of-compilation and forward reference errors

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2010-03-17T01:39:00Z
Last change time
2014-02-15T02:42:36Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bugzilla
Depends on
190, 4753

Comments

Comment #0 by bugzilla — 2010-03-17T01:39:39Z
I've run into this while working on std.process. Take the following two files: // This is a.d: import std.stdio; // This is process.d: module std.process; import std.stdio; void foo(File f = std.stdio.stdin); Compile them in the order they're written here, and you get a nonsensical error: lars@neutrino:~/tmp$ dmd -c a.d process.d process.d(3): Error: cannot implicitly convert expression (stdin) of type File to File Make the following change to process.d: module std.process; import std.stdio: File, stdin; // Selective imports now void foo(File f = std.stdio.stdin); This causes an additional forward reference error: lars@neutrino:~/tmp$ dmd -c a.d process.d process.d(2): Error: alias std.process.stdin forward reference of stdin process.d(3): Error: cannot implicitly convert expression (stdin) of type File to File Compile them in reverse order, and it works fine in both cases: lars@neutrino:~/tmp$ dmd -c process.d a.d Note: I'm marking this as a blocker because it's rather crucial to the new std.process design, and I don't want to muck about with Andrei's makefile just to make it compile.
Comment #1 by clugdbug — 2010-06-09T23:57:00Z
This is a weird bug, but it seems to be caused by having a module with the same name as one in the standard library. If you change the module statement to (for example) module.std.process2; the problem disappears. Since this is obscure (you probably won't encounter it unless you're working on Phobos!) and has a trivial workaround, downgrading from blocker.
Comment #2 by bugzilla — 2010-06-10T00:18:56Z
I agree, the workaround is trivial up to the point where you want to include the module in Phobos. But that's exactly where I am now. I can build Phobos with the module in question by changing the order of modules in the makefile, but it's very fragile. When I try to run the unittests, for instance, the bug reappears.
Comment #3 by bugzilla — 2010-07-20T11:41:52Z
Anxious to get this extremely annoying problem fixed, I've finally been able to reduce it to a small test case: // This is a.d module a; import b; struct Foo {} Foo foo; // This is b.d module b; import a; void fun(Foo f = a.foo); Compilation gives: $ dmd -c a.d b.d b.d(4): Error: cannot implicitly convert expression (foo) of type Foo to Foo Phew! It took a while, hopefully it's worth it.
Comment #4 by r.sagitario — 2010-07-20T13:24:50Z
Now, it very much looks like bug 190 with the forward reference hidden in the cyclic import.
Comment #5 by destructionator — 2010-08-16T07:40:21Z
Has anyone tried Rainer's patch in bug 190 to see if it fixes this?
Comment #6 by r.sagitario — 2010-08-16T08:15:19Z
(In reply to comment #5) > Has anyone tried Rainer's patch in bug 190 to see if it fixes this? Yes, I did and it works for the reduced test case, too. Can't tell about the original report, though.
Comment #7 by bugzilla — 2010-08-17T00:46:28Z
It does indeed fix the original problem. Thanks, Rainer! Any chance we can get this into the next release?
Comment #8 by bugzilla — 2010-08-27T16:06:37Z
Comment #9 by schveiguy — 2010-09-08T05:33:34Z
Reopened, Walter reverted the changes that fix this in http://www.dsource.org/projects/dmd/changeset/652 It appears that 4753 has an updated patch, can be applied soon?
Comment #10 by bugzilla — 2011-01-03T02:58:32Z
Fixed again, along with bug 190. Both the original and reduced test cases now compile successfully. http://www.dsource.org/projects/dmd/changeset/842