packageless modules == pure evil? Answer: No
Bill Baxter
dnewsgroup at billbaxter.com
Sun Feb 17 19:40:02 PST 2008
Bill Baxter wrote:
> torhu wrote:
>> Bill Baxter wrote:
>>> The problem that prompted this message was that I had a module called
>>> just "blas" in one place and was trying to make another module called
>>> "dflat.blas". But that breaks plain "import blas". It picks up the
>>> "dflat.blas" rather than the packageless blas, even though I didn't
>>> specify that I wanted "dflat.blas".
>>
>> It works when I try a simple test. I have a.d, b/a.d, and then import
>> just 'a' into test.d.
>>
>> a.d:
>> ---
>> module a;
>>
>> char[] s = "a";
>> ---
>>
>> b/a.d:
>> ---
>> module b.a;
>>
>> char[] s = "b.a";
>> ---
>>
>> test.d:
>> ---
>> import std.stdio;
>> import a;
>>
>> void main()
>> {
>> writefln(s);
>> }
>> ---
>>
>> running:
>> ---
>> c:\prog\test\D\baxter>bud -exec test
>> a
>> ---
>>
>> So a more complex test is needed to show the problem. Maybe importing
>> from different include paths, etc?
>
> Ok, thanks for helping me to work through this, torhu.
>
> There may not be any pure evil going on here. In trying to make a
> simple repro I've found that if I get rid of the top level a.d (or move
> it into a different subdir without using a -I to find it), I get the
> highly misleading error message:
>
> "b\c.d(4): module b.a is in multiple packages b.a"
>
> So this could be the root of the problem. I think that was the error I
> was seeing previously that made me thing it was mixing up the two
> modules. I'll dig in a little more and report what I find.
>
> --bb
Here's a version that causes the problem. It actually seems to be an
issue with build tools rather than DMD itself.
If you put 'test' inside 'b' and then try to build from there with the
-I.. flag, the build tools get confused over the two different a.d files.
It seems both bud and dsss get confused about this situation and end up
only using one of the a's. What's interesting is the failure modes are
quite different.
Attached is a zip with the setup.
> cd packageless\b
> bud -full testit
Gives error:
--> testit.d(4): module b.a is in multiple packages b.a
> cd packageless\b
> dsss build testit
> testit
Builds fine, but outputs "b.a" instead of "a". This is what I was
seeing -- the wrong module gets imported (b.a instead of a).
The problem goes away if you build from the 'packageless' dir one level
up instead:
> cd packageless
> bud -full b\testit
> testit
Prints "a" as expected.
So the final moral of the story is either:
1) don't put test programs in the same directory as package.
-or at least-
2) don't build test programs from inside the package directory.
--bb
-------------- next part --------------
A non-text attachment was scrubbed...
Name: packageless.zip
Type: application/octet-stream
Size: 1392 bytes
Desc: not available
Url : http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20080218/dfafd4bf/attachment.obj
More information about the Digitalmars-d-learn
mailing list