www.digitalmars.com         C & C++   DMDScript  

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

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 puremagic.com
        ReportedBy: opantm2+dbugs gmail.com



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: -------
Oct 26 2013