www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16132] New: std.variant.VariantN does not work with a class

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 puremagic.com
          Reporter: gmanev72 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.

--
Jun 06 2016