On 31.03.2018 18:34, Simen Kjærås wrote:
On Saturday, 31 March 2018 at 13:34:18 UTC, Kagamin wrote:
On Friday, 30 March 2018 at 13:56:45 UTC, Stefan Koch wrote:
Ah that is an interesting bug which further demonstrates that templates are a tricky thing :) Basically you cannot _generally_ proof that one template just forwards to another.
Therefore you have to create separate types.
And since you create separate types the alias is not an alias but a separate template. Solving this may be possible for special cases but in the general case is infeasible.

If a template is used as a type it should be resolved to a type, no? And template resolves to a type in a straightforward way. Where does it fail? Judging by the error message "cannot deduce function from argument types !()(TestType!int)" it does successfully resolve alias to a type.

You're starting in the wrong end - the type cannot yet be considered, since the compiler doesn't know the correct arguments to TestAlias. Given this code:

struct S(T...) {}
alias SS(T...) = S!(T, int);

void foo(T)(SS!T arg) {}

unittest {
     foo(SS!string());
}

The error message is "template foo cannot deduce function from argument types !()(S!(string, int)), candidates are: foo(T)(SS!T arg)".
...

If the compiler were to do something other than give up, we would need some algorithm to define what it should try, and in which order.

It should simply run a limited semantic analysis on the function parameters before matching.

void foo(T)(SS!T arg) -> void foo(T)(S!(T, int) arg)

To support Ilya's use case, it suffices to expand unconstrained alias templates.

Reply via email to