www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Cannot Instantiate SumType

reply surlymoor <surlymoor cock.li> writes:
I'm experiencing an error when instantiating `SumType` with an 
aggregate template that itself is instantiated with a void 
function. In other words...
```d
struct Foo(alias f) {}
// As the error implies, altering it to be non-void makes 
everything copacetic~
void bar() {}
alias S = SumType!(Foo!bar);
```
The error in question...
```
Error: variable 
`std.typecons.ReplaceTypeUnless!(isSumTypeInstance, This, 
SumType!(Foo!(bar)), Foo!(bar)).F!(bar).replaceTemplateArgs` type 
`void` is inferred from initializer `bar()`, and variables cannot 
be of type `void`
```
Perhaps I'm dong something stupid, or failing to realize, because 
all the glue sniffing I did when I was younger has finally 
manifested itself, but if it's not, is there a workaround?
Sep 20 2021
parent reply Paul Backus <snarwin gmail.com> writes:
On Monday, 20 September 2021 at 11:21:28 UTC, surlymoor wrote:
 The error in question...
 ```
 Error: variable 
 `std.typecons.ReplaceTypeUnless!(isSumTypeInstance, This, 
 SumType!(Foo!(bar)), Foo!(bar)).F!(bar).replaceTemplateArgs` 
 type `void` is inferred from initializer `bar()`, and variables 
 cannot be of type `void`
 ```
Looks like this is a bug in `ReplaceType`: ```d import std.typecons; struct Foo(alias f) {} void bar() {} alias _ = ReplaceType!(int, int, Foo!bar); ``` I've submitted a bug report here: https://issues.dlang.org/show_bug.cgi?id=22325 [1]: https://phobos.dpldocs.info/std.typecons.ReplaceType.html
Sep 20 2021
parent surlymoor <surlymoor cock.li> writes:
On Monday, 20 September 2021 at 15:33:23 UTC, Paul Backus wrote:
 On Monday, 20 September 2021 at 11:21:28 UTC, surlymoor wrote:
 The error in question...
 ```
 Error: variable 
 `std.typecons.ReplaceTypeUnless!(isSumTypeInstance, This, 
 SumType!(Foo!(bar)), Foo!(bar)).F!(bar).replaceTemplateArgs` 
 type `void` is inferred from initializer `bar()`, and 
 variables cannot be of type `void`
 ```
Looks like this is a bug in `ReplaceType`: ```d import std.typecons; struct Foo(alias f) {} void bar() {} alias _ = ReplaceType!(int, int, Foo!bar); ``` I've submitted a bug report here: https://issues.dlang.org/show_bug.cgi?id=22325 [1]: https://phobos.dpldocs.info/std.typecons.ReplaceType.html
Thanks, Paul. Glad to see the fix is simple.
Sep 20 2021