D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 620 - Can't use property syntax with a template function
Summary: Can't use property syntax with a template function
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: Walter Bright
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2006-11-30 03:15 UTC by Bill Baxter
Modified: 2020-08-11 05:45 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Bill Baxter 2006-11-30 03:15:51 UTC
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
}
Comment 1 Simen Kjaeraas 2010-10-01 15:25:37 UTC
Could we please get this one fixed? Especially now with opDispatch, this is a painful one.
Comment 2 Trass3r 2010-10-29 03:52:29 UTC
Yeah opDispatch could be used for vector swizzling setters.
Comment 3 Simen Kjaeraas 2010-10-31 12:29:14 UTC
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!
    }
}
Comment 4 Alex Khmara 2011-01-01 22:22:42 UTC
(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".
Comment 5 Kenji Hara 2011-07-29 06:29:13 UTC
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
Comment 6 github-bugzilla 2012-01-26 12:06:20 UTC
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
Comment 7 Walter Bright 2012-01-26 17:12:27 UTC
Fixed for D2.
Comment 8 Don 2012-11-12 23:48:20 UTC
Closing since fixed on D2.
Comment 9 Dlang Bot 2020-08-11 05:45:06 UTC
dlang-community/DCD pull request #622 "Fix #620" was merged into master:

- dbc9d82f708f18354d5ba26e5efbcf2997c6ba11 by Hackerpilot:
  Update several dependencies.
  
  libdparse: Get support for 'throw' as a function attribute
  dsymbol: A bug fix that will fix issue 620
  msgpack-d: Fix some deprecations and some build issues on Windows
  containers: Some bug fixes.

https://github.com/dlang-community/DCD/pull/622