www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22325] New: ReplaceType fails on templated type instantiated


          Issue ID: 22325
           Summary: ReplaceType fails on templated type instantiated with
                    void-returning function
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

As of DMD 2.097.2, the following program fails to compile:

import std.typecons;

struct Foo(alias f) {}
void bar() {}
alias _ = ReplaceType!(int, int, Foo!bar);

The error message is:

/usr/include/dmd/phobos/std/typecons.d(9067): Error: variable
`std.typecons.ReplaceTypeUnless!(false_, int, int,
Foo!(bar)).F!(bar).replaceTemplateArgs` type `void` is inferred from
initializer `bar()`, and variables cannot be of type `void`
/usr/include/dmd/phobos/std/meta.d-mixin-794(794): Error: template instance
`std.typecons.ReplaceTypeUnless!(false_, int, int, Foo!(bar)).F!(bar)` error
/usr/include/dmd/phobos/std/typecons.d(9071):        instantiated from here:
`staticMap!(replaceTemplateArgs, bar)`
/usr/include/dmd/phobos/std/typecons.d(9012):        instantiated from here:
`ReplaceTypeUnless!(false_, int, int, Foo!(bar))`
bug.d(5):        instantiated from here: `ReplaceType!(int, int, Foo!(bar))`

Sep 20 2021