On Sunday, 8 January 2023 at 05:42:46 UTC, Qusatlegadus wrote:
auto s = 1234.to!string.map!q{a - '0'}.sum;
works fine.
but if i do an alias
alias comb = to!string.map!q{a - '0'}
Error: unknown, please file report on issues.dlang.org
What's wrong with this
## Simple explanation
`to!string` is a function expecting 1 argument, which you're not
providing in your alias. Convert your alias to a lambda
expression:
```D
alias comb = x => x.to!string.map!q{a - '0'}
```
## Complicated explanation
`to` is a template defined like this:
```D
// https://github.com/dlang/phobos/blob/master/std/conv.d
template to(T)
{
T to(A...)(A args)
if (A.length > 0)
{
return toImpl!T(args);
}
// some overloads omitted for brevity
}
```
`to` needs at least 2 template arguments - the first one for the
outer template is passed explicitly (what you did with
`to!string`), the other ones are inferred from the arguments
passed to the `to` function. Since you did not pass an argument
to `to!string`, the inner template doesn't get instantiated.
Basically what happens is you're trying to pass an uninstantiated
template as argument to `map`. This is quite an exotic situation,
so probably there isn't a dedicated error message for it or
you're hitting a bug in the compiler (hence the unknown error
message).