Bug 9971 – eponymous function is not an lvalue

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-04-20T15:56:00Z
Last change time
2013-05-06T23:11:45Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
ellery-newcomer

Comments

Comment #0 by ellery-newcomer — 2013-04-20T15:56:31Z
the code: void main() { goo!()(); } void goo()() { auto g = &goo; // not ok } void goo2() { auto g = &goo2; // ok } the fireworks: Error: goo()() is not an lvalue dmd 2.063-devel.
Comment #1 by maxim — 2013-04-20T21:19:50Z
I think it does not work because &goo is address of raw template and dmd does not instantiate it, so you should use pointer to instantiated function. I am not sure this is bug (but it may be an enhancement request).
Comment #2 by ellery-newcomer — 2013-04-20T22:17:10Z
(In reply to comment #1) > I think it does not work because &goo is address of raw template and dmd does > not instantiate it, so you should use pointer to instantiated function. I am > not sure this is bug (but it may be an enhancement request). It is inconsistent with the way templated structs and classes work: void main() { alias T!(int) t1; } struct T(j) { pragma(msg, "a struct ",T); // T is the struct } pragma(msg, "a template ", T); // T is the template
Comment #3 by maxim — 2013-04-20T22:32:39Z
(In reply to comment #2) > It is inconsistent with the way templated structs and classes work: > > void main() { > alias T!(int) t1; > } > > struct T(j) { > pragma(msg, "a struct ",T); // T is the struct > } > pragma(msg, "a template ", T); // T is the template Sorry I don't see your point. Note, that second message is printed irrespective to instantiation and none of the messages is sensitive to what T is really is. void main() { alias T!(int) t1; } struct T(j) { //pragma(msg, "a struct ",T); // T is the struct pragma(msg, T.stringof); } //pragma(msg, "a template ", T); // T is the template pragma(msg, T.stringof);
Comment #4 by ellery-newcomer — 2013-04-20T22:45:05Z
(In reply to comment #3) > > Sorry I don't see your point. Note, that second message is printed irrespective > to instantiation and none of the messages is sensitive to what T is really is. My point is that inside the struct template, T without any template instantiation refers to the instantiated struct: import std.traits; void main() { alias T!(int) t1; } struct T(j) { T foo() { T t; return t; } } static assert(is(ReturnType!(T!int.foo) == T!int)); static assert(is(ReturnType!(T!double.foo) == T!double)); But in a templated function, T refers to the template:
Comment #5 by deadalnix — 2013-04-20T22:49:27Z
(In reply to comment #1) > I think it does not work because &goo is address of raw template and dmd does > not instantiate it, so you should use pointer to instantiated function. I am > not sure this is bug (but it may be an enhancement request). No, within the function, the function must be resolve before the template.
Comment #6 by k.hara.pg — 2013-04-20T23:10:56Z
I think this is a bug. Inside template function, the name 'goo' should be resolved to the instantiated function 1st, then rewritten to template 'goo' if needed. For example, this code should work. void main() { goo(1); // 1. instantiate goo!int } void goo(T...)(T args) { auto g = &goo; // 2. &goo!int == void function(int) // 4. &goo!() == void function() pragma(msg, typeof(g)); static if (T.length) goo(args[1..$]); // 3. instantiate goo!() }
Comment #7 by maxim — 2013-04-20T23:41:27Z
Yes, you are both right.
Comment #8 by k.hara.pg — 2013-05-06T04:52:56Z
Comment #9 by github-bugzilla — 2013-05-06T20:41:58Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f34c77f6f19ea516c19842f2aff0e43a7d94c3ef fix Issue 9971 - eponymous function is not an lvalue https://github.com/D-Programming-Language/dmd/commit/654de7808e89204d20bac6f7f228fe07e3dd2c7a Merge pull request #1970 from 9rnsr/fix9971 Issue 9971 - eponymous function is not an lvalue