Possible bug when instantiating template function with nested struct

Teodor Dutu teodor.dutu at gmail.com
Sun Nov 7 19:49:13 UTC 2021


On Sunday, 7 November 2021 at 18:15:53 UTC, Stanislav Blinov 
wrote:
> ??? No, it will not. The problem in your
>
> ```d
> Tarr1 _d_arrayctor(Tarr1 : T1[], Tarr2 : T2[], T1, T2)(scope 
> Tarr2 from)
> {
>     Tarr1 to;
>     // ...
>     return to;
> }
> ```
>
> is the default initialization. S from the unittest is a nested 
> struct, and can't be instantiated outside of scope of its 
> parent. But this should work:
>
> ```d
> [...]
> Tarr1 to = void;
> [...]
> ```

Thanks a lot! It worked.

>> I used `@trusted` because some unittests that used this 
>> lowering were `@safe`. It was a compile-time workaround.
>
> ? It should pass unittests without lying to the compiler, by 
> correctly inferring @safe-ty.

Yes, you're right. `@trusted` was more of a stop-gap solution in 
order to get the code to work in the first place. Now that it 
does, I should look into a nicer way of having `@safe`-ty 
inferred. I'll probably follow your advice here, too. Thanks 
again!


More information about the Digitalmars-d mailing list