summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/fail_compilation/ice12574.d
blob: 420b6b70078135cc0247112e9953fc501f7cb6fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
TEST_OUTPUT:
---
fail_compilation/ice12574.d(40): Error: tuple index `2` exceeds length 2
fail_compilation/ice12574.d(53): Error: template instance `ice12574.reduce!("a", "a").reduce!(Tuple!(int, int, int))` error instantiating
---
*/

struct Tuple(T...)
{
    alias Types = T;
    T field;
    alias field this;
}
Tuple!A tuple(A...)(A args) { return typeof(return)(args); }

template binaryFun(alias fun)
{
    static if (is(typeof(fun) : string))
    {
        auto binaryFun(ElementType1, ElementType2)(auto ref ElementType1 __a, auto ref ElementType2 __b)
        {
            mixin("alias "~"a"~" = __a ;");
            mixin("alias "~"b"~" = __b ;");
            return mixin(fun);
        }
    }
    else
    {
        alias binaryFun = fun;
    }
}

template reduce(fun...)
{
    auto reduce(Seed)(Seed result)
    {
        foreach (i, Unused; Seed.Types)
        {
           result[i] = binaryFun!(fun[i])(1, 1); // here
        }
        return result;
    }
}

int foo(int value)
{
    return value;
}

void main()
{
    reduce!("a", "a")(tuple(1, 1, 1));
}