Bug 22325 – ReplaceType fails on templated type instantiated with void-returning function
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-09-20T15:32:46Z
Last change time
2021-09-20T21:42:38Z
Keywords
pull
Assigned to
No Owner
Creator
Paul Backus
Comments
Comment #0 by snarwin+bugzilla — 2021-09-20T15:32:46Z
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 instantiating
/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))`
---
Comment #1 by dlang-bot — 2021-09-20T18:18:22Z
@pbackus created dlang/phobos pull request #8248 "Fix Issue 22325 - ReplaceType fails on templated type instantiated wi…" fixing this issue:
- Fix Issue 22325 - ReplaceType fails on templated type instantiated with void-returning function
Previously, when recursing into a type's template arguments,
ReplaceTypeUnless would mistakenly attempt to evaluate a template alias
parameter as an expression. In cases where the alias parameter was not a
valid expression or could not be evaluated at compile time, this caused
a compilation failure; in other cases, it caused ReplaceTypeUnless to
give an incorrect result.
This change makes ReplaceTypeUnless correctly treat template alias
parameters as aliases.
https://github.com/dlang/phobos/pull/8248
Comment #2 by dlang-bot — 2021-09-20T21:42:38Z
dlang/phobos pull request #8248 "Fix Issue 22325 - ReplaceType fails on templated type instantiated wi…" was merged into master:
- 44257f132ca99a16a34e475f844e93e3822d231c by Paul Backus:
Fix Issue 22325 - ReplaceType fails on templated type instantiated with void-returning function
Previously, when recursing into a type's template arguments,
ReplaceTypeUnless would mistakenly attempt to evaluate a template alias
parameter as an expression. In cases where the alias parameter was not a
valid expression or could not be evaluated at compile time, this caused
a compilation failure; in other cases, it caused ReplaceTypeUnless to
give an incorrect result.
This change makes ReplaceTypeUnless correctly treat template alias
parameters as aliases.
https://github.com/dlang/phobos/pull/8248