Bug 4617 – Alias this'ed symbols cannot be passed to templates

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-08-10T22:38:00Z
Last change time
2013-03-04T02:04:27Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
rsinfu
Blocks
8321

Comments

Comment #0 by rsinfu — 2010-08-10T22:38:03Z
DMD tries to evaluate alias this'ed symbols. It causes a compile error on instantiating templates with alias this'ed symbols. -------------------- test1.d alias Test!(S.square) test; struct S { struct F { int square(int n) { return n*n; } real square(real n) { return n*n; } } F forward; alias forward this; } template Test(alias k) {} -------------------- % dmd -o- -c test1.d test1.d(1): Error: function test1.S.F.square (int n) is not callable using argument types () test1.d(1): Error: expected 1 function arguments, not 0 % _ -------------------- TemplateInstance::semanticTiargs() (or TypeQualified::resolveHelper()) resolves forwarded symbols as dotvar expressions and tries to evaluate them at compile time. Apparently, it causes the problem. The error does not occur if the symbol is forwarded directly: -------------------- test2.d alias Test!(S.square) test; struct S { struct F { int square(int n) { return n*n; } real square(real n) { return n*n; } } F forward; alias forward.square square; // okay } template Test(alias k) {} -------------------- % dmd -o- -c test2.d % _ --------------------
Comment #1 by rsinfu — 2010-08-10T22:39:48Z
The bug also causes a false negative of __traits(isSame), becuase isSame reuses the same algorithm as template instantiation: -------------------- test3.d static assert( __traits(isSame, S.square, S.forward.square) ); struct S { struct F { int square(int n) { return n*n; } real square(real n) { return n*n; } } F forward; alias forward this; } -------------------- % dmd -o- -c test3.d test3.d(1): Error: static assert (__traits(isSame,forward.square,square)) is false --------------------
Comment #2 by k.hara.pg — 2012-06-30T05:07:55Z