Thread overview
With statement problems
Aug 25, 2018
Shigeki Karita
Aug 26, 2018
Mike Franklin
Oct 13, 2018
karita
August 25, 2018
A with statement shows several counterintuitive results. I want to know that it is compiler bugs or spec defects.

- a with statement has higher priority than UFCS at inner scopes

this might conflict with 19.26.5 "When UFCS rewrite is necessary, compiler searches the name on accessible module level scope, in order from the innermost scope" and 11.19.1 "Within the with body the referenced object is searched first for identifier symbols"

- a with statement hides outer scope overloads

this might be bug. 11.19.6 says "In nested WithStatements, the inner-most scope takes precedence. If a symbol cannot be resolved at the inner-most scope, resolution is forwarded incrementally up the scope hierarchy." and 19.26.5 grantees compiler to find UFCS overload in outer scopes.

I made running example here
https://wandbox.org/permlink/gdnfyQyDewmOAzVi


related specs
https://docarchives.dlang.io/v2.081.0/spec/function.html#pseudo-member
https://docarchives.dlang.io/v2.081.0/spec/statement.html#with-statement

August 26, 2018
On Saturday, 25 August 2018 at 05:52:13 UTC, Shigeki Karita wrote:
> A with statement shows several counterintuitive results. I want to know that it is compiler bugs or spec defects.
>
> - a with statement has higher priority than UFCS at inner scopes
>
> this might conflict with 19.26.5 "When UFCS rewrite is necessary, compiler searches the name on accessible module level scope, in order from the innermost scope" and 11.19.1 "Within the with body the referenced object is searched first for identifier symbols"
>
> - a with statement hides outer scope overloads
>
> this might be bug. 11.19.6 says "In nested WithStatements, the inner-most scope takes precedence. If a symbol cannot be resolved at the inner-most scope, resolution is forwarded incrementally up the scope hierarchy." and 19.26.5 grantees compiler to find UFCS overload in outer scopes.
>
> I made running example here
> https://wandbox.org/permlink/gdnfyQyDewmOAzVi
>
>
> related specs
> https://docarchives.dlang.io/v2.081.0/spec/function.html#pseudo-member
> https://docarchives.dlang.io/v2.081.0/spec/statement.html#with-statement

I'm not seeing the problem you're trying to illustrate.  IMO, if there is an ambiguity, the symbol with the most local scope should take precedence.  If there is an ambiguity with types, the symbol with the most specific type should take precedence.

Can you create an example that shows the above not happening?

Mike
October 13, 2018
On Sunday, 26 August 2018 at 05:48:30 UTC, Mike Franklin wrote:
> On Saturday, 25 August 2018 at 05:52:13 UTC, Shigeki Karita wrote:
>> [...]
>
> I'm not seeing the problem you're trying to illustrate.  IMO, if there is an ambiguity, the symbol with the most local scope should take precedence.  If there is an ambiguity with types, the symbol with the most specific type should take precedence.
>
> Can you create an example that shows the above not happening?
>
> Mike

Thanks for making it clear. The problem is second one "if there is an ambiguity, the symbol with the most local scope should take precedence."

I reported tiny example and this problem to bugzilla https://issues.dlang.org/show_bug.cgi?id=19305