Bug 2131 – Template scope access

Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-05-25T06:29:53Z
Last change time
2019-09-09T13:43:02Z
Assigned to
No Owner
Creator
Simen Kjaeraas

Comments

Comment #0 by simen.kjaras — 2008-05-25T06:29:53Z
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.
Comment #1 by razvan.nitu1305 — 2019-09-09T13:43:02Z
Templates are evaluated in the context where they are instantiated. If a template needs a specific symbol it is cleaner to declare in the templates' scope rather than creating symbol resolution rules for templates. Closing on the same grounds as issue 2125.