www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9971] New: eponymous function is not an lvalue

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9971

           Summary: eponymous function is not an lvalue
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: ellery-newcomer utulsa.edu


--- Comment #0 from Ellery Newcomer <ellery-newcomer utulsa.edu> 2013-04-20
15:56:31 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 20 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9971


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim maxim-fomin.ru


--- Comment #1 from Maxim Fomin <maxim maxim-fomin.ru> 2013-04-20 21:19:50 PDT
---
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).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9971



--- Comment #2 from Ellery Newcomer <ellery-newcomer utulsa.edu> 2013-04-20
22:17:10 PDT ---
(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 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9971



--- Comment #3 from Maxim Fomin <maxim maxim-fomin.ru> 2013-04-20 22:32:39 PDT
---
(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); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9971



--- Comment #4 from Ellery Newcomer <ellery-newcomer utulsa.edu> 2013-04-20
22:45:05 PDT ---
(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: -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9971


deadalnix <deadalnix gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |deadalnix gmail.com


--- Comment #5 from deadalnix <deadalnix gmail.com> 2013-04-20 22:49:27 PDT ---
(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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9971



--- Comment #6 from Kenji Hara <k.hara.pg gmail.com> 2013-04-20 23:10:56 PDT ---
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!()
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9971



--- Comment #7 from Maxim Fomin <maxim maxim-fomin.ru> 2013-04-20 23:41:27 PDT
---
Yes, you are both right.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 20 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9971


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid


--- Comment #8 from Kenji Hara <k.hara.pg gmail.com> 2013-05-06 04:52:56 PDT ---
https://github.com/D-Programming-Language/dmd/pull/1970

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 06 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9971



--- Comment #9 from github-bugzilla puremagic.com 2013-05-06 20:41:58 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 06 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9971


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 06 2013