Bug 6185 – Include non-global functions when resolving UFCS

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-06-20T15:55:00Z
Last change time
2014-12-14T06:06:25Z
Keywords
pull
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2011-06-20T15:55:20Z
Note: Function imports is a new feature that's currently in DMD's github repo, it's not in 2.053, but it's going to be in 2.054. module test; void main() { } void foo() { import std.utf; "foo".toUTF16z; } Error: undefined identifier module test.toUTF16z
Comment #1 by bearophile_hugs — 2012-01-21T19:41:29Z
*** Issue 7344 has been marked as a duplicate of this issue. ***
Comment #2 by k.hara.pg — 2012-01-22T05:30:13Z
Before 2.053, "foo".toUTF16z is rewritten to toUTF16("foo"); After 2.054, it is rewitten to .toUTF16("foo"); Therefore current D2 requires module level function for UFCS. But I don't know it is right behavior.
Comment #3 by bearophile_hugs — 2012-01-22T07:07:32Z
(In reply to comment #2) > Before 2.053, "foo".toUTF16z is rewritten to toUTF16("foo"); > After 2.054, it is rewitten to .toUTF16("foo"); What's bad in rewriting it as toUTF16("foo")?
Comment #4 by k.hara.pg — 2012-01-22T08:07:51Z
(In reply to comment #3) > (In reply to comment #2) > > Before 2.053, "foo".toUTF16z is rewritten to toUTF16("foo"); > > After 2.054, it is rewitten to .toUTF16("foo"); > > What's bad in rewriting it as toUTF16("foo")? Ah, sorry, it is my mistake. Replace 'toUTF16' to 'toUTF16z'.
Comment #5 by bearophile_hugs — 2012-01-22T09:05:49Z
(In reply to comment #4) > Ah, sorry, it is my mistake. Replace 'toUTF16' to 'toUTF16z'. What's bad in rewriting it as toUTF16z("foo")?
Comment #6 by k.hara.pg — 2012-01-24T05:58:30Z
(In reply to comment #5) > (In reply to comment #4) > > > Ah, sorry, it is my mistake. Replace 'toUTF16' to 'toUTF16z'. > > What's bad in rewriting it as toUTF16z("foo")? I found an original issue and commit revision. - Issue 2344 - Two wrong lookups for array functions Posted by Andrei, and Walter added a fix in dmd 2.020. - https://github.com/D-Programming-Language/dmd/commit/f87c229d#L7L5774 Changed the conversion result of array.id(args) into from id(array,args) to .id(array,args) I think that Walter's fix was not enough. UFCS lookup should search *innermost and valid* function, and in the lookup process, invalid matches should be ignored. From issue 2344: ---- size_t blah(int[] r) { return r.length; } struct A { int[] r; size_t blah() { return r.blah(); } // try A.blah(r) -> it is invalid, so should be ignored. // try .blah(r) -> it is valid, so UFCS lookup should match this. } void main() { A a; a.blah; } ---- This strategy also work for function local imports.
Comment #7 by k.hara.pg — 2012-01-24T06:01:13Z
(In reply to comment #2) > Before 2.053, "foo".toUTF16z is rewritten to toUTF16("foo"); > After 2.054, it is rewitten to .toUTF16("foo"); > Therefore current D2 requires module level function for UFCS. > > But I don't know it is right behavior. Sorry, I had said mistake. The turning point was 2.020, not 2.054.
Comment #8 by bugzilla — 2012-01-31T23:13:25Z
It currently works as specified, so this is an enhancement request, not a bug.
Comment #9 by bugzilla — 2012-01-31T23:14:13Z
*** Issue 4525 has been marked as a duplicate of this issue. ***
Comment #10 by andrej.mitrovich — 2012-12-27T09:03:02Z
*** Issue 9216 has been marked as a duplicate of this issue. ***
Comment #11 by yebblies — 2013-01-02T00:34:52Z
*** Issue 8692 has been marked as a duplicate of this issue. ***
Comment #12 by yebblies — 2013-01-02T00:35:09Z
*** Issue 8834 has been marked as a duplicate of this issue. ***
Comment #13 by public — 2013-01-26T14:49:51Z
Is it possible to get "preapproved" on this? Quite inconvenient to add global imports only to use UFCS.
Comment #14 by andrej.mitrovich — 2013-02-15T08:19:03Z
*** Issue 9515 has been marked as a duplicate of this issue. ***
Comment #15 by k.hara.pg — 2013-04-24T21:52:30Z
https://github.com/D-Programming-Language/dmd/pull/1930 By the compiler change, this code void main() { import std.utf; "foo".toUTF16z; } Would be changed to valid, but // from issue 4525 class Foo { void bar(string s) {} void foo() { string str = "hello"; str.bar(); } } Would be kept invalid. Issue 8692, issue 8834, and issue 9515 are same.
Comment #16 by bearophile_hugs — 2013-04-25T04:38:11Z
(In reply to comment #15) > but > > // from issue 4525 > class Foo > { > void bar(string s) {} > void foo() > { > string str = "hello"; > str.bar(); > } > } > > Would be kept invalid. Is this a temporary limit or is this meant to remain as a permanent D wart?
Comment #17 by k.hara.pg — 2013-04-25T05:11:28Z
(In reply to comment #16) > (In reply to comment #15) > > > but > > > > // from issue 4525 > > class Foo > > { > > void bar(string s) {} > > void foo() > > { > > string str = "hello"; > > str.bar(); > > } > > } > > > > Would be kept invalid. > > Is this a temporary limit or is this meant to remain as a permanent D wart? I think it would be never allowed. It would re-open the bug 2344.
Comment #18 by bearophile_hugs — 2013-04-25T05:55:14Z
(In reply to comment #17) > I think it would be never allowed. It would re-open the bug 2344. OK. I think that probably there is a way to solve those problems. But I also think that to solve them you probably have to introduce complex rules with corner cases (see C++ templates). So probably a small wart in a simpler language is better that a complex feature that almost works.
Comment #19 by github-bugzilla — 2013-05-06T00:39:38Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bb8b47d9168fde3c258eeb0d30a8b5e93ff9c684 fix Issue 6185 - Include non-global functions when resolving UFCS
Comment #20 by yebblies — 2014-12-14T06:06:25Z
*** Issue 13730 has been marked as a duplicate of this issue. ***