Bug 900 – changing import order causes type mismatch

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-01-28T10:47:00Z
Last change time
2014-02-16T15:24:09Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
torhu

Comments

Comment #0 by torhu — 2007-01-28T10:47:45Z
Tested with DMD 1.0 and 1.004 on winxp. There are 4 files involved: // palette.d module palette; struct RGB { } ========================================= // color_inl.d module color_inl; //uncommenting this line will fix the problem //import palette : RGB: import color; void _set_color(RGB* p) { } ========================================= // color.d module color; // swapping the order of these two lines will also fix the problem public import color_inl; import palette : RGB; ========================================= // dtest.d import color; void fade() { RGB rgb; _set_color(&rgb); } void main() {} ======================================== C:\prog\test\D\bugtest>dmd test.d test.d(6): function color_inl._set_color (int,RGB*) does not match parameter types (int,RGB *) test.d(6): Error: cannot implicitly convert expression (& rgb) of type RGB * to RGB*
Comment #1 by torhu — 2007-01-29T02:34:47Z
Are selective imports private by default or not? The docs state that imports are public by default, but also says that selective imports are "bound into the current namespace". I take it they are supposed to be private, which means this bug is really about the compiler accepting invalid code, since color_inl.d and dtest.d are able to use RGB without importing palette.d.
Comment #2 by larsivar — 2007-01-29T03:59:27Z
Imports are private by default, if the spec says anything else, create a bug report for it.
Comment #3 by torhu — 2007-01-29T17:42:52Z
(In reply to comment #2) The problem is that I don't know if "bound into the current namespace" implies that it's also automatically exported as part of the importing module. Probably it shouldn't imply that, since the point of selective imports seems to be to avoid name conflicts in the importing module. But this still confuses me, so I think there should be a clarification in the docs. At least so we know what is correct when the compiler is somewhere in between.
Comment #4 by torhu — 2007-04-03T13:00:33Z
(In reply to comment #2) A couple of bug reports here that suggest that selective, static, and renamed imports are meant to be be private. http://d.puremagic.com/issues/show_bug.cgi?id=604 http://d.puremagic.com/issues/show_bug.cgi?id=314 The question remains whether this is intended, or not. In DMD, they are currently public. Were they supposed to be private? The docs don't say.
Comment #5 by leandro.lucarella — 2009-11-13T15:50:57Z
I think the spec is quite clear: [...] Public Imports By default, imports are private. [...] http://www.digitalmars.com/d/1.0/module.html#ImportDeclaration Static, renamed and selective import are all *import*, so it looks like they all should be private by default (for the same reason basic imports are). This bug is old and doesn't look very useful, I think it should be closed.
Comment #6 by Jesse.K.Phillips+D — 2010-03-29T16:42:17Z
I seem to have run across this in DMD 2.042. Here a static assert fails with the error: ===================== C:\opt\dmd\windows\bin\..\..\src\phobos\std\typecons.d(424): Error: static assert (is(Tuple!(string,float) == Tuple!(string,float))) is false C:\opt\dmd\windows\bin\..\..\src\phobos\std\typecons.d(413): instantiated from here: Tuple!(string,float) C:\opt\dmd\windows\bin\..\..\src\phobos\std\typecons.d(423): instantiated from here: slice!(1,3) C:\opt\dmd\windows\bin\..\..\src\phobos\std\typecons.d(420): instantiated from here: Tuple!(int,string,float,double) C:\opt\dmd\windows\bin\..\..\src\phobos\std\regex.d(260): instantiated from here: Tuple!(string,string) C:\opt\dmd\windows\bin\..\..\src\phobos\std\regex.d(280): instantiated from here: opCall!(string) C:\opt\dmd\windows\bin\..\..\src\phobos\std\regex.d(1519): instantiated from here: Regex!(char).\test2.d(7): instantiated from here: regex!(string) =================== -------------------------- // Place string after import test2 to make this work import std.string; import test2; void main() { new TestMe(); } ------------------------------ -------------------- module test2; import std.regex; class TestMe { void test(string input) { auto foo = !match(input, regex("fish")).empty; } }
Comment #7 by Jesse.K.Phillips+D — 2010-04-15T14:23:31Z
My import issue is no longer in DMD 2.043, but the original submission's code still doesn't work.
Comment #8 by code — 2012-02-14T05:03:30Z
This is invalid because 'import palette : RGB;' introduces RGB as private alias. You cannot access it from color_inl. Changing that to 'public import palette : RGB' will fix your problem.
Comment #9 by code — 2012-02-14T05:29:54Z
Sorry, I was using a wrong dmd version. Changing it to 'public import palette : RGB' will fail because of a forward reference error. This happens due to the cyclic import of color and color_inc.
Comment #10 by andrei — 2013-11-15T20:34:29Z
This seems to have been fixed, possibly a while ago.