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 }
Could we please get this one fixed? Especially now with opDispatch, this is a painful one.
Yeah opDispatch could be used for vector swizzling setters.
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! } }
(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".
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
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
Fixed for D2.
Closing since fixed on D2.
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