[Issue 2179] New: import inside class works but is not in spec
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 26 11:52:16 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2179
Summary: import inside class works but is not in spec
Product: D
Version: 1.028
Platform: PC
OS/Version: Windows
Status: NEW
Keywords: spec
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: wbaxter at gmail.com
DMD accepts imports placed inside of class scopes. This is useful for template
mixins because it means you can put the imports needed by the mixin into the
template itself.
However it doesn't seem to be allowed by the grammar in the spec. It is
useful, and it works, and therefore I think the grammar should be updated to
reflect this.
Here's the test case:
----
module miximport;
import std.stdio;
class Foo {
import miximport_imp;
this() {
writefln("Hi there from Inner - magic value: %s", magic_value);
}
}
void main() { new Foo; }
----
Running dmd -v gives this, which includes miximport_imp in the list of imports:
----
F:\bax\Code\d\play>dmd -v miximport.d
parse miximport
semantic miximport
import object (f:\usr\pkg\d\dmd\bin\..\import\tango\object.di)
import std.stdio (f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\stdio.d)
import std.compat (f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\compat.d)
import tango.stdc.stdio
(f:\usr\pkg\d\dmd\bin\..\import\tango\tango\stdc\stdio.d)
import tango.stdc.stdarg
(f:\usr\pkg\d\dmd\bin\..\import\tango\tango\stdc\stdarg.d)
import tango.stdc.stddef
(f:\usr\pkg\d\dmd\bin\..\import\tango\tango\stdc\stddef.d)
import tango.stdc.config
(f:\usr\pkg\d\dmd\bin\..\import\tango\tango\stdc\config.d)
import std.c.stdio (f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\c\stdio.d)
import std.format (f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\format.d)
import std.stdarg (f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\stdarg.d)
import tango.core.Vararg
(f:\usr\pkg\d\dmd\bin\..\import\tango\tango\core\Vararg.d)
import std.c.stdarg
(f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\c\stdarg.d)
import std.utf (f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\utf.d)
import std.c.stdlib
(f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\c\stdlib.d)
import std.stdint (f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\stdint.d)
import std.c.stddef
(f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\c\stddef.d)
import tango.stdc.errno
(f:\usr\pkg\d\dmd\bin\..\import\tango\tango\stdc\errno.d)
import std.c.string
(f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\c\string.d)
import std.string (f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\string.d)
import std.uni (f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\uni.d)
import std.array (f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\array.d)
import tango.core.Exception
(f:\usr\pkg\d\dmd\bin\..\import\tango\tango\core\Exception.di)
import std.ctype (f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\ctype.d)
import std.gc (f:\usr\pkg\d\dmd\bin\..\import\tangobos\std\gc.d)
import tango.core.Memory
(f:\usr\pkg\d\dmd\bin\..\import\tango\tango\core\Memory.di)
import miximport_imp (miximport_imp.d)
semantic2 miximport
semantic3 miximport
code miximport
function this
function main
----
The spec could be fixed, by for instance sticking ImportDeclaration under
ClassBodyDeclaration.
A similar issue may pertain to structs, but I haven't tried that.
Relevant discussions of this elsewhere include:
* http://www.dsource.org/projects/dsss/ticket/193
* http://www.dsource.org/forums/viewtopic.php?p=20054#20054
If it is decided that the spec is correct, and this is not legal, then it
should be made an error. But I will note that there are libraries in existence
that depend on this behavior (namely doost,
http://www.dsource.org/projects/doost). There maybe be others, but that's the
one where I ran across it.
--
More information about the Digitalmars-d-bugs
mailing list