Bug 4525 – Regression(2.020) Array member call syntax can't find matches in current class
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-07-28T12:44:00Z
Last change time
2012-02-01T22:23:40Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bus_dbugzilla
Comments
Comment #0 by bus_dbugzilla — 2010-07-28T12:44:54Z
This works fine in 1.062, but fails in 2.047 (has also been tested to fail in 2.042, 2.046):
module mymodule;
class Foo
{
void bar(string s) {}
void foo()
{
string str = "hello";
str.bar();
}
}
Compiler output for 2.047:
mymodule.d(9): Error: undefined identifier module mymodule.bar
Comment #1 by bus_dbugzilla — 2010-07-28T12:47:37Z
Don has reported that "It worked in 2.012 and earlier, but failed in 2.020. I don't have any intermediate versions installed."
Comment #2 by bus_dbugzilla — 2010-07-29T13:37:35Z
Further investigation shows that this is not a bug.
array.func(arguments)
is rewritten to be:
.func(array, arguments)
Note the leading ., which means look for func() at module scope. Foo.bar() in
the example is not at module scope, hence it is not found. Note that the error
message gives the clue in referring to "mymodule.bar", not just "bar".
This was a deliberate design choice, as universal function call syntax is a
feature meant to be used with global functions, not local ones.
Comment #6 by k.hara.pg — 2012-01-31T22:51:48Z
(In reply to comment #5)
> Further investigation shows that this is not a bug.
>
> array.func(arguments)
>
> is rewritten to be:
>
> .func(array, arguments)
>
> Note the leading ., which means look for func() at module scope. Foo.bar() in
> the example is not at module scope, hence it is not found. Note that the error
> message gives the clue in referring to "mymodule.bar", not just "bar".
>
> This was a deliberate design choice, as universal function call syntax is a
> feature meant to be used with global functions, not local ones.
The original bug issue against paired the change is bug 2344. But finding UFCS property/member function from global scope causes problems like this issue.
And the finding rule is not work against function local import, see bug 6185.
My suggestion is here:
http://d.puremagic.com/issues/show_bug.cgi?id=6185#c6
- The UFCS lookup should start *from most inside scope*, not module scope.
- Until reaching to module scope, UFCS lookup should not raise errors against mismatches of invalid function call, instead *ignore* them silently.
- Finally, if there is no match in all scopes, raise an error.
Comment #7 by bugzilla — 2012-01-31T23:14:13Z
Since the current behavior matches the spec, redesigning the behavior would be an enhancement request. This makes it a duplicate of bug 6185.
*** This issue has been marked as a duplicate of issue 6185 ***
Comment #8 by yebblies — 2012-02-01T22:23:40Z
*** Issue 5567 has been marked as a duplicate of this issue. ***