Bug 11364 – Variant fails to compile with const(TypeInfo).
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-26T13:15:00Z
Last change time
2015-06-09T01:31:14Z
Assigned to
opantm2+dbugs
Creator
opantm2+dbugs
Comments
Comment #0 by opantm2+dbugs — 2013-10-26T13:15:29Z
Not entirely sure the cause of this. The following code fails to compile:
import std.variant;
void main() {
const(TypeInfo) ti = typeid(TypeInfo);
Variant v = ti;
}
Output:
rdmd test.d
/Users/kapps/dev/dmd/phobos/std/variant.d(333): Error: mutable method object.TypeInfo.opCmp is not callable using a const object
/Users/kapps/dev/dmd/phobos/std/variant.d(377): Error: mutable method object.TypeInfo.opCmp is not callable using a const object
/Users/kapps/dev/dmd/phobos/std/variant.d(600): Error: template instance std.variant.VariantN!(32LU).VariantN.handler!(const(TypeInfo)) error instantiating
/Users/kapps/dev/dmd/phobos/std/variant.d(550): instantiated from here: opAssign!(const(TypeInfo))
test.d(16): instantiated from here: __ctor!(const(TypeInfo))
/Users/kapps/dev/dmd/phobos/std/variant.d(550): Error: template instance std.variant.VariantN!(32LU).VariantN.opAssign!(const(TypeInfo)) error instantiating
test.d(16): instantiated from here: __ctor!(const(TypeInfo))
test.d(16): Error: template instance std.variant.VariantN!(32LU).VariantN.__ctor!(const(TypeInfo)) error instantiating
Seems like it tries to call opCmp with the const instance even if opCmp is not const.
Yet the following sample works:
import std.variant;
class Foo {
override int opCmp(Object o) { return 0; }
override bool opEquals(Object o) { return 0; }
}
void main() {
const(Foo) inst = new Foo();
Variant v = inst;
}
Not entirely sure why it doesn't work with TypeInfo then which has the exact same opCmp and opEquals signatures.
Comment #1 by opantm2+dbugs — 2014-03-28T19:59:32Z