Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement proper UFCS name look up #1930

Merged
merged 3 commits into from
May 6, 2013
Merged

Conversation

9rnsr
Copy link
Contributor

@9rnsr 9rnsr commented Apr 25, 2013

In basic, UFCS name search looks for only symbols in module scope.
If the enclosing scopes have local imports, the imported overload-set and selected/renamed symbols should also be considered in searching.

In my opinion, UFCS should not see the locally declared symbols (in statement scope and aggregate member scope). So, currently, this is a final step for the UFCS implementation.


Fixed bugzilla issue:
Issue 6185 - Include non-global functions when resolving UFCS

@ghost
Copy link

ghost commented Apr 25, 2013

What about static methods, will they be taken into account? E.g.:

struct S
{
    static int square(int val) { return val * val; }
    int s() { return 2.square; }  // OK or NG?
}

9rnsr added 3 commits April 25, 2013 18:49
…named imports

Keep `AliasDeclaration::import` even after resolving forward refs.
In basic, UFCS name search looks for only symbols in module scope.
If the enclosing scopes have local imports, the imported overload-set and
selected/renamed symbols should also be considered in searching.

In my opinion, UFCS should not see the locally declared symbols (in
statement scope and aggregate member scope). So, currently, this is a
final step for the UFCS implementation.
@9rnsr
Copy link
Contributor Author

9rnsr commented Apr 25, 2013

As I wrote in the summary, I finally decided that UFCS should only see the symbols declared in module scope, and I implemented it.
All of static methods in aggregate scope are not declared in the module scope, so they are not considered.

It looks like unneeded limitation, but I think this is reasonable. My reasons are:

  1. UFCS is not for syntactic sugar.
    The static method is properly accessible from the method of aggregates. You can call it with normal function call syntax. UFCS is not necessary there.
  2. It is not the purpose of UFCS.
    As far as I know, the original purpose of UFCS is for the ability to add retrofit auxiliary methods/properties to the existing types. Such auxiliary utilities should be declared in module scope, to make them accessible from other modules.
  3. Keep compiler implementation simple.
    static methods and non-static ones are overloadable in D. Until resolve overloading, we cannot detect the function is really static or not. In name lookup phase, the elements of overloaded symbols should not be considered.

WalterBright added a commit that referenced this pull request May 6, 2013
Implement proper UFCS name look up
@WalterBright WalterBright merged commit 08faeba into dlang:master May 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants