First draft: added with-colon statement

matheus matheus at gmail.com
Sun Jan 19 13:39:26 UTC 2025


On Sunday, 19 January 2025 at 05:25:15 UTC, Walter Bright wrote:
> On 1/18/2025 1:19 PM, qxi wrote:
>> In current implementation if there is multiple 'with:' in same 
>> scope then last 'with:' take precedence and I think multiple 
>> 'with:' in the same scope should have the equal precedence.
>> 
>> '''
>> enum E1{ A,B }
>> 
>> enum E2{ B,C }
>> 
>> {
>>    with (E1):
>>    B;  // E1.B
>> 
>>    with (E2):
>> 
>>    A;  // E1.A
>>    C;  // E2.C
>>    B;  // this should be error because 2 matched symbols 
>> 'E1.B' and 'E2.B'
>> }
>> '''
>
>
> The example is equivalent to:
> ```
> enum E1{ A,B }
>
> enum E2{ B,C }
>
> {
>    with (E1)
>    {
>      B;  // E1.B
>
>      with (E2)
>      {
>        A;  // E1.A
>        C;  // E2.C
>        B;  // (*)
>      }
>    }
> }
> '''
> and B should resolve as E2.B because of the usual scoping 
> rules. Changing the scoping rules would be different from other 
> uses of : that introduce scope.


There is a caveat there for my understanding, because with 
current/old statement:

import std;

struct S1{ int A;}
struct S2{ int A;}

void main(){
     S1 s1 = {A : 1};
     S2 s2 = {A : 2};

     with(s1){
         writeln(A); // 1
         with (s2)
        		writeln(A); // 2
         writeln(A); // 1
     }
}

Now this could be confusing with ":" and the order of precedence, 
I think qxi has a point.

Matheus.


More information about the dip.development mailing list