[Issue 16132] New: std.variant.VariantN does not work with a class that inherits from a template instantiation

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jun 6 07:37:41 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16132

          Issue ID: 16132
           Summary: std.variant.VariantN does not work with a class that
                    inherits from a template instantiation
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: gmanev72 at hotmail.com

The following code does not compile. The error is:
../src/phobos/std/variant.d(546,9): Error: static assert  "Cannot store a C in
a VariantN!(8LU, C)"


   interface I(T) {
   }

   class C : I!int {
   }

   auto c = new C;
   Algebraic!C a = c;


Most probably the cause is how AllowedTypes is determined. It uses
std.typecons.ReplaceType to replace This with VariantN.

Here is a short repro of the cause:

   import std.typecons;
   static assert(is(ReplaceType!(int, string, C) == I!string));

So the type C is replaced with I!int in VariantN.AllowedTypes.

--


More information about the Digitalmars-d-bugs mailing list