[Issue 2028] New: Can't create template class in module of same name
Jarrett Billingsley
kb3ctd2 at yahoo.com
Thu Apr 24 13:37:29 PDT 2008
<d-bugmail at puremagic.com> wrote in message
news:bug-2028-3 at http.d.puremagic.com/issues/...
> http://d.puremagic.com/issues/show_bug.cgi?id=2028
>
> Summary: Can't create template class in module of same name
> Product: D
> Version: 2.012
> Platform: PC
> OS/Version: Linux
> Status: NEW
> Severity: normal
> Priority: P2
> Component: DMD
> AssignedTo: bugzilla at digitalmars.com
> ReportedBy: jlquinn at us.ibm.com
>
>
> I'm not sure this is a bug or a language limitation, but it feels like a
> bug...
>
> I have 2 modules:
>
> a.d:
> class a(T) {}
>
> b.d:
> import a;
> class b {
> a!(int) x;
> }
>
> When I try to compile this, I get the following error:
>
> ~/dmd/bin/dmd -c a.d b.d
> b.d(4): template instance a is not a template declaration, it is a import
> b.d(4): Error: a!(int) is used as a type
> b.d(4): variable b.b.x voids have no value
>
> Why can't I do this?
I don't think it's a "bug" but just a sort of unintuitive bit of symbol
lookup.
In b.d, when you import a, it creates an entry in b's symbol table that maps
from 'a' to 'module a'. It also creates entries for all the symbols inside
'module a', except for anything that conflicts. So when you refer to 'a' in
'module b', it refers to 'module a' and not 'class a'.
This is only a problem if the class (or really any symbol) name is the same
as the *top-level name* of a module. So if you instead had "mylib.a" as the
name of the module, accessing 'class a' would not be a problem. Of course,
then accessing a symbol named "mylib" would.
More information about the Digitalmars-d-bugs
mailing list