Bug 620 – Can't use property syntax with a template function

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2006-11-30T03:15:51Z
Last change time
2020-08-11T05:45:06Z
Keywords
patch
Assigned to
Walter Bright
Creator
Bill Baxter

Comments

Comment #0 by wbaxter — 2006-11-30T03:15:51Z
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 by simen.kjaras — 2010-10-01T15:25:37Z
Could we please get this one fixed? Especially now with opDispatch, this is a painful one.
Comment #2 by hoganmeier — 2010-10-29T03:52:29Z
Yeah opDispatch could be used for vector swizzling setters.
Comment #3 by simen.kjaras — 2010-10-31T12:29:14Z
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 by alex.khmara — 2011-01-01T22:22:42Z
(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 by k.hara.pg — 2011-07-29T06:29:13Z
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 by github-bugzilla — 2012-01-26T12:06:20Z
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 by bugzilla — 2012-01-26T17:12:27Z
Fixed for D2.
Comment #8 by clugdbug — 2012-11-12T23:48:20Z
Closing since fixed on D2.
Comment #9 by dlang-bot — 2020-08-11T05:45:06Z
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