Bug 9515 – UFCS fails with local aliases

Status
REOPENED
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-14T20:37:15Z
Last change time
2024-12-13T18:04:07Z
Assigned to
No Owner
Creator
Jonathan M Davis
Moved to GitHub: dmd#17573 →

Comments

Comment #0 by issues.dlang — 2013-02-14T20:37:15Z
This code import std.algorithm; void main() { alias std.algorithm.find f; f("hello", 'c'); "hello".f('c'); } fails to compile, giving this error q.d(7): Error: undefined identifier 'f' Note that the call which doesn't use UFCS works, but the one which does fails to compile. If the alias is moved outside of the function, then both compile.
Comment #1 by andrej.mitrovich — 2013-02-15T08:18:59Z
*** This issue has been marked as a duplicate of issue 6185 ***
Comment #2 by andrej.mitrovich — 2014-03-22T15:06:44Z
Pull for 6185 did not fix this, so I'm reopening the issue.
Comment #3 by k.hara.pg — 2014-03-23T17:15:58Z
UFCS is not designed to work for local symbols. http://dlang.org/function#pseudo-member
Comment #4 by issues.dlang — 2014-03-23T18:28:11Z
> UFCS is not designed to work for local symbols. It may very well be an enhancement rather than a bug to get it working with local symbols, but given that we're trying to make it so that there's no real difference between local imports and module-level imports (aside from the scope of the import), I'd say that we should definitely get UFCS working with local imports. It follows the whole "turtles all the way down" principle that we're generally striving for. Certainly, I don't know why we wouldn't implement this. It should simply be a question of someone taking the initiative to get it done rather than whether we should do it or not.
Comment #5 by k.hara.pg — 2014-03-23T18:45:17Z
(In reply to comment #4) > > UFCS is not designed to work for local symbols. > [snip] > Certainly, I don't know why we wouldn't implement this. My concern case is: import std.array; struct MyRange(E) { E[] data; E front() { return data.front; // If UFCS could see local symbols, the inner-most 'front' will be chosen // and this line will be rewritten to this.front(data). } } Note that, in symbol lookup phase function static-ness is not considered. Because functions could be overloaded, and it should be resolved in later phase.
Comment #6 by andrej.mitrovich — 2014-03-24T06:30:13Z
(In reply to comment #4) > > UFCS is not designed to work for local symbols. > > It may very well be an enhancement rather than a bug to get it working with > local symbols, but given that we're trying to make it so that there's no real > difference between local imports and module-level imports (aside from the scope > of the import), I'd say that we should definitely get UFCS working with local > imports. To be precise: local imports work, it's local symbols that don't work. This works ok: ----- void main() { import std.array; assert([].empty); } ----- But this doesn't: ----- void main() { bool empty(T)(T[]) { return true; } assert([].empty); } -----
Comment #7 by robert.schadek — 2024-12-13T18:04:07Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17573 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB