[Issue 23272] New: [REG2.099] CTFE error of typeid comparison ==
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jul 27 23:17:05 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23272
Issue ID: 23272
Summary: [REG2.099] CTFE error of typeid comparison ==
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: regression
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: johanengelen at weka.io
Unfortunately a rather large testcase:
Testcase:
```
import std.string;
import std.conv;
import std.traits;
import std.typetuple;
struct SumType(Ts...) {
mixin(() {
auto s = "enum Cases : ubyte {";
foreach(i, _; Ts) {
s ~= "c" ~ text(i) ~ " = " ~ text(i) ~ ", ";
}
return s ~= "unset}\n";
}());
Cases which = Cases.unset;
union {
Ts cases;
}
auto ref opAssign(U)(auto ref U val) {
enum idx = staticIndexOf!(Unqual!U, Ts);
cases[idx] = val;
which = cast(Cases)idx;
return this;
}
}
auto caseOfTemplated(alias func, T)(auto ref T s) {
final switch (s.which) foreach(i, CASE; EnumMembers!(T.Cases)) {
case CASE:
static if (CASE == T.Cases.unset) {
assert (false, "not set");
} else {
return func(s.cases[i]);
}
}
assert (false);
}
void foo() {
bool validate() {
SumType!(string, int) s;
s = "hello";
assert (caseOfTemplated!(a => typeid(a))(s) == typeid(string));
return true;
}
static assert(validate());
}
```
Compilation fails with since dlang2.099 (works for older frontend versions):
/opt/compiler-explorer/ldc1.29.0/ldc2-1.29.0-linux-x86_64/bin/../import/object.d(329):
Error: cannot convert `&object.TypeInfo` to `Object*` at compile time
/opt/compiler-explorer/ldc1.29.0/ldc2-1.29.0-linux-x86_64/bin/../import/object.d(329):
called from here: `opEquals(*& lhs, *& rhs)`
<source>(47): called from here: `opEquals(caseOfTemplated(s),
typeid(string))`
<source>(50): called from here: `validate()`
<source>(50): while evaluating: `static assert(validate())`
--
More information about the Digitalmars-d-bugs
mailing list