SumType alias can't be deduced?

Emmanuelle VuLXn6DBW at PPtUm7TvV6nsw.com
Mon Feb 21 18:43:18 UTC 2022


See https://run.dlang.io/is/hNaSFh:

```d
import std.sumtype;

struct Unit {}
alias Option(T) = SumType!(T, Unit);

void foobar(T)(Option!T option) {}

void main() {
     foobar(Option!int(123));
}
```

If you run this, the compiler should emit this error:

```d
onlineapp.d(14): Error: template `onlineapp.foobar` cannot deduce 
function from argument types `!()(SumType!(int, Unit))`
onlineapp.d(8):        Candidate is: `foobar(T)(Option!T option)`
```

If you change `foobar`’s parameter’s type from `Option!T` to 
`SumType!(T, Unit)`, it  compiles without error.

Surely this is not intended? Is this a compiler bug or am I doing 
something wrong?

Cheers!



More information about the Digitalmars-d-learn mailing list