www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21124] New: Multiple templated is expressions used with


          Issue ID: 21124
           Summary: Multiple templated is expressions used with logical
           Product: D
           Version: D2
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: john.michael.hall gmail.com

The code below fails to compile because the template parameter U is in both is
statements in isFoo. The code for isFoo2, which changes the U in the second is
statement, compiles without error. 

I see nothing in the specification that would suggest that isFoo should fail to
compile, though I may have missed it. Nevertheless, there is a workaround.

struct Foo(T)
    T x;

struct Foo(T, U)
    T x;

enum bool isFoo(T) = is(T : Foo!(U), U) || is(T : Foo!(U, V), U, V);
enum bool isFoo2(T) = is(T : Foo!(U), U) || is(T : Foo!(W, V), W, V);

void main()
    static assert(isFoo!(Foo!(int)));
    static assert(isFoo!(Foo!(int, int)));
    static assert(isFoo2!(Foo!(int)));
    static assert(isFoo2!(Foo!(int, int)));

Aug 05 2020