Why can I call a function with mismatched parameter type?

vit vit at vit.vit
Fri Dec 11 11:36:05 UTC 2020


On Friday, 11 December 2020 at 11:25:22 UTC, Andrey Zherikov 
wrote:
> Here is the example:
>     alias f1 = (string  ) {}; f1(int   .init);
>     alias f2 = (string s) {}; f2(int   .init);
>     alias f3 = (int     ) {}; f3(string.init);
>     alias f4 = (int i   ) {}; f4(string.init);
>
> "f1" case compiles successfully and all others are not (error 
> is "is not callable using argument types").
>
> Question is why does f1 case compile?
>
> Furthermore even these do compile:
>     f1(float.init);
>
>     struct S{}
>     f1(S.init);



alias f1 = (string  ) {}

"string" isn't type, but name of variable with generic type:

alias f1 = (/*auto type*/ string) {}


More information about the Digitalmars-d-learn mailing list