Thread overview
[Issue 620] New: Can't use property syntax with a template function
Nov 30, 2006
d-bugmail
Oct 01, 2010
Simen Kjaeraas
Oct 29, 2010
Trass3r
Oct 31, 2010
Simen Kjaeraas
Jan 02, 2011
Alex Khmara
Jul 29, 2011
Kenji Hara
Jan 27, 2012
Walter Bright
Nov 13, 2012
Don
November 30, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=620

           Summary: Can't use property syntax with a template function
           Product: D
           Version: 0.175
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: wbaxter@gmail.com


I'd like to call this a bug, but I can't find any place in the spec that states this should work.  However it seems logical that it would work given that the property magic is just syntactic sugar that treats foo=x as a regular function call foo(x).

---------------
int g_value;

void valuef(int v) {  g_value = v; }

void valuet(T)(T v) { g_value = v; }

void main()
{
    valuef = 42; // ok
    valuet = 42; // Error: valuet is not an lvalue
                 // Error: cannot implicitly convert expression (42) of type
int to void
}


-- 

October 01, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=620


Simen Kjaeraas <simen.kjaras@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simen.kjaras@gmail.com


--- Comment #1 from Simen Kjaeraas <simen.kjaras@gmail.com> 2010-10-01 15:25:37 PDT ---
Could we please get this one fixed? Especially now with opDispatch, this is a painful one.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=620


Trass3r <mrmocool@gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrmocool@gmx.de


--- Comment #2 from Trass3r <mrmocool@gmx.de> 2010-10-29 03:52:29 PDT ---
Yeah opDispatch could be used for vector swizzling setters.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 31, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=620



--- Comment #3 from Simen Kjaeraas <simen.kjaras@gmail.com> 2010-10-31 12:29:14 PDT ---
Some hacking about showed me that opDispatch has a workaround for this problem, by using a two-layer approach:

template opDispatch( string name ) {
    auto opDispatch( T... )( T args ) {
        // Do something!
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 26, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=620


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |bugzilla@digitalmars.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 02, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=620


Alex Khmara <alex.khmara@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alex.khmara@gmail.com


--- Comment #4 from Alex Khmara <alex.khmara@gmail.com> 2011-01-01 22:22:42 PST ---
(In reply to comment #3)
> Some hacking about showed me that opDispatch has a workaround for this problem, by using a two-layer approach:
> 
> template opDispatch( string name ) {
>     auto opDispatch( T... )( T args ) {
>         // Do something!
>     }
> }

This workaroung is only partial. This code produces "Error: s.opDispatch(T...)
has no value".

import std.stdio;

struct S {
    template opDispatch( string name ) {
        string opDispatch( T... )( T args ) {
            return "bar";
        }
    }
}

void main() {
    S s;
    string str = s.foo;
}

Same if I try "auto opDispatch" instead of "string".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=620


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |k.hara.pg@gmail.com


--- Comment #5 from Kenji Hara <k.hara.pg@gmail.com> 2011-07-29 06:29:13 PDT ---
I think this is not enhancement at least D2.
opDispatch for property syntax needs fixing this issue.

struct S
{
    template opDispatch(string name)
    {
        @property int opDispatch(A...)(A args)
        {
          static if (args.length)
            return args[0];
          else
            return 0;
        }
    }
}
void main()
{
    S s;
    s.prop == 0;  // Error: s.opDispatch(A...) has no value
}

I have posted D2 patch. https://github.com/D-Programming-Language/dmd/pull/280

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 26, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=620



--- Comment #6 from github-bugzilla@puremagic.com 2012-01-26 12:06:20 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/8bc639fb00cab9002b91a1d900ddd72f56f993a4 Merge pull request #280 from 9rnsr/propDispatch

Issue 620 - Can't use property syntax with a template function

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=620


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|0.175                       |D1


--- Comment #7 from Walter Bright <bugzilla@digitalmars.com> 2012-01-26 17:12:27 PST ---
Fixed for D2.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 13, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=620


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
            Version|D1                          |D2
         Resolution|                            |FIXED


--- Comment #8 from Don <clugdbug@yahoo.com.au> 2012-11-12 23:48:20 PST ---
Closing since fixed on D2.

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