[Issue 2131] New: Template scope access
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun May 25 04:29:55 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2131
Summary: Template scope access
Product: D
Version: 2.014
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: simen.kjaras at gmail.com
In my post "Template alias parameter mixin import inference" (
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=68798
), and in bug 2125 ( http://d.puremagic.com/issues/show_bug.cgi?id=2125,
"Moving a template to a separate module breaks compilation" ), it is
demonstrated that giving a template access to both its declaration scope and
its instantiation scope might give more logical and desireable behavior.
Example code:
//////////////////////
module a;
import std.stdio;
template bar()
{
int i;
void func()
{
writefln(i);
}
}
void main()
{
foo!(bar) a;
a.func();
}
//////////////////////
module b;
struct foo(alias T)
{
mixin T!();
}
//////////////////////
Gives error message "b.d(5): Error: undefined identifier writefln".
Currently, this can be fixed by placing import statements within the template
declaration, but allowing access to more scopes would make it easier for the
programmer.
--
More information about the Digitalmars-d-bugs
mailing list