aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/compilable/ice12554.d
blob: 76452f462dcbb0d1d3a877f69597cf776df0fbe7 (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
// REQUIRED_ARGS: -o-
// PERMUTE_ARGS:

void main() pure
{
    int[] foo;

    // if indirectly instantiated aggregate is struct (== MapResultS)
    foo.map!(MapResultS, x => foo.map!(MapResultS, y => x).array);

    // if indirectly instantiated aggregate is class (== MapResultC)
    foo.map!(MapResultC, x => foo.map!(MapResultC, y => x).array);
}

T array(T)(T a)
{
    static int g; g = 1;    // impure operation
    return a;
}

template map(alias MapResult, fun...)
{
    auto map(Range)(Range r)
    {
        alias AppliedReturnType(alias f) = typeof(f(r[0]));
        static assert(!is(AppliedReturnType!fun == void));

        return MapResult!(fun).init;
    }
}

struct MapResultS(alias fun)
{
    @property front()
    {
        return fun(1);
    }
}

class MapResultC(alias fun)
{
    @property front()
    {
        return fun(1);
    }
}