Rules for Symbol Name Lookup seem contradictory

user1234 user1234 at 12.de
Mon Jun 22 02:16:52 UTC 2020


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.


More information about the Digitalmars-d-learn mailing list