www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.internals - With statement problems

reply Shigeki Karita <shigekikarita gmail.com> writes:
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
Aug 24 2018
parent reply Mike Franklin <slavo5150 yahoo.com> writes:
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
Aug 25 2018
parent karita <shigekikarita gmail.com> writes:
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
Oct 12 2018