Bug 15764 – Name lookup within (eponymous?) template doesn't check outside the template

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-03-05T02:46:35Z
Last change time
2023-02-13T14:56:39Z
Assigned to
No Owner
Creator
Shriramana Sharma

Comments

Comment #0 by samjnaa — 2016-03-05T02:46:35Z
Ref: http://forum.dlang.org/post/[email protected] string ta(string s) { return s ~ "1"; } template ta(string s) { enum ta = .ta(s); } void main() { import std.stdio; writeln(ta("a"), ' ', ta!"b"); } outputs "a1 b1" as expected. So the compiler is in general able to identify when a symbol refers to a function and when a template, but if I remove the . before the ta(s) *within* the template ta, it gives an error: <src>(2): Error: forward reference of variable ta <src>(6): Error: template instance <src>.ta!"b" error instantiating This seems to be a minor limitation (and maybe not of terribly high priority) that symbol lookup within an (eponymous?) template doesn't look outside the template for other possible compatible symbols and requires a preceding "." to tell it to look at top-level.
Comment #1 by razvan.nitu1305 — 2023-02-13T14:56:39Z
The problem here is that when `ta(s)` is resolved, the first scope that is searched for `ta` is the current scope and the `ta` symbol is already defined as an enum. This sort of situation is precisely why the dot operator was added. The alternative would be to special case the implementation for such situations. As a conclusion, this is a WONTFIX. The compilers does the correct thing.