Bug 2344 – Two wrong lookups for array functions

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2008-09-07T13:33:00Z
Last change time
2015-06-09T05:14:51Z
Assigned to
bugzilla
Creator
andrei

Comments

Comment #0 by andrei — 2008-09-07T13:33:04Z
size_t blah(int[] r) { return r.length; } struct A { int[] r; size_t blah() { return r.blah(); } } void main() { A a; a.blah; } The code above says: function test.A.blah () does not match parameter types (int[]) Error: expected 0 arguments, not 1 So it looks like the compiler first morphs r.blah() into blah(r), but then uses the local scope to look for blah. Therefore A.blah will be found, leading to the nonsensical call this.blah(r). Interestingly, if the parens are removed leaving r.blah, the lookup is still wrong but in a different way: Error: no property 'blah' for type 'int[]' So this time the call fails to start with. Both errors are bugs. The code should compile with and without parentheses.
Comment #1 by bugzilla — 2008-10-10T18:23:06Z
This is an enhancement. Rewriting: array.foo as: .foo(array) rather than: foo(array) does the trick.
Comment #2 by andrei — 2008-10-10T20:34:45Z
(In reply to comment #1) > This is an enhancement. Rewriting: > array.foo > as: > .foo(array) > rather than: > foo(array) > does the trick. > Nah. The whole point was to have obj.foo work for arrays and other beasts.
Comment #3 by bugzilla — 2008-10-20T22:21:37Z
Fixed dmd 2.020
Comment #4 by yebblies — 2012-02-01T07:18:48Z
*** Issue 1457 has been marked as a duplicate of this issue. ***