[Issue 11364] New: Variant fails to compile with const(TypeInfo).

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Oct 26 13:15:31 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11364

           Summary: Variant fails to compile with const(TypeInfo).
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: opantm2+dbugs at gmail.com


--- Comment #0 from Kapps <opantm2+dbugs at gmail.com> 2013-10-26 13:15:29 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list