[Issue 19703] std.typecons.ReplaceType wrongly evaluates alias this
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Feb 26 23:18:17 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19703
Simen Kjaeraas <simen.kjaras at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |simen.kjaras at gmail.com
Summary|Algebraic doesn't work with |std.typecons.ReplaceType
|alias this of templated |wrongly evaluates alias
|type |this
--- Comment #1 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
Reduced example:
import std.typecons : ReplaceType;
struct S1(int n) { }
struct S2 {
S1!4 s1;
alias s1 this;
}
static assert(is(ReplaceType!(int, int, S2)[0] == S2));
The problem is this line in std.typecons:
https://github.com/dlang/phobos/blob/13705f53bd3322168de5701d64a5f7c8cf791867/std/typecons.d#L8682
It aggressively matches alias this where it shouldn't.
It should check if T[0]'s alias this is what's being matched instead of T[0]
itself. Here's one possible fix:
private template isAliasThis(T, alias U, V...) {
static foreach (at; __traits(getAliasThis, T)) {
static if (is(typeof(__traits(getMember, T, at)) : U!V)) {
enum isAliasThis = true;
}
}
static if (!__traits(compiles, assert(isAliasThis))) {
enum isAliasThis = false;
}
}
And replacing the offending line with this:
else static if (is(T[0] : U!V, alias U, V...) && !isAliasThis!(T, U, V))
--
More information about the Digitalmars-d-bugs
mailing list