summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/nested-optional.slang
blob: 8fdeac33bf6611921d67e0662e407699dcc03bba (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
//TEST:INTERPRET(filecheck=CHECK):

Optional<Optional<int>> getNone() { return none; }

void main()
{
    Optional<Optional<Optional<int>>> val = Optional<Optional<int>>(5);
    Optional<Optional<Optional<int>>> defaultVal1 = none;
    Optional<Optional<Optional<int>>> defaultVal2 = getNone();

    // CHECK: 8
    printf("%d\n", sizeof(val));

    // CHECK: success
    if (defaultVal1.hasValue == defaultVal2.hasValue)
    {
        printf("success\n");
    }
    else
    {
        printf("failure\n");
    }

    // CHECK: value: 5
    if (let x = val)
    {
        if (let y = x)
        {
            if (let z = y)
            {
                printf("value: %d\n", z);
            }
        }
    }
}