Re: Rules for Symbol Name Lookup seem contradictory

2020-06-22 Thread Manfred Nowak via Digitalmars-d-learn

On Monday, 22 June 2020 at 02:16:52 UTC, user1234 wrote:
[...]

Maybe that the spec is a bit vague as it doesn't mention that

[...]
A vague place in a spec is usually called "Dark Corner" and the 
functionality then marked as "Implementation defined".


But this mark is missing here.

And restricting the validity of the contradictory seeming 
sentences to overloadables only, puts all others into an 
unregulated state.


Therefore the stated problem stays unexplained.


Re: Rules for Symbol Name Lookup seem contradictory

2020-06-21 Thread user1234 via Digitalmars-d-learn

On Monday, 22 June 2020 at 01:38:41 UTC, Manfred Nowak wrote:
https://dlang.org/spec/module.html#name_lookup contains under 
4.3.4 only two sentences.


While the first sentence explains, that the search ends
  "as soon as a matching symbol is found",
the second sentence implies that the search may continue until 
it is sure, that

  no other symbol "with the same name" can be found
in the current phase.

This means, that under sentence one the following code is free 
of errors and under sentence two the following code has to be 
rejected, because an ambiguity exists.


De facto the code compiles without error under dmd v2.092.1:

class C{
}
class D{
  C c;
  this(){
auto c= new C;
  }
}
void main(){
  auto d= new D;
}


Classes (non templatized) cannot be overloaded so in your example 
the rule that applies is that the one from the most inner scope 
is selected.
For functions and templates this is another story. As they can be 
part of overload set, they are all selected by name and then 
tried with the arguments (template or call args) and if two 
matches then the error happens.


Maybe that the spec is a bit vague as it doesn't mention that 
rules for lookups of non overloadable symbols are more simple.


Rules for Symbol Name Lookup seem contradictory

2020-06-21 Thread Manfred Nowak via Digitalmars-d-learn
https://dlang.org/spec/module.html#name_lookup contains under 
4.3.4 only two sentences.


While the first sentence explains, that the search ends
  "as soon as a matching symbol is found",
the second sentence implies that the search may continue until it 
is sure, that

  no other symbol "with the same name" can be found
in the current phase.

This means, that under sentence one the following code is free of 
errors and under sentence two the following code has to be 
rejected, because an ambiguity exists.


De facto the code compiles without error under dmd v2.092.1:

class C{
}
class D{
  C c;
  this(){
auto c= new C;
  }
}
void main(){
  auto d= new D;
}