aboutsummaryrefslogtreecommitdiff
path: root/compiler/tests/parser/def_type_broken.bad
blob: f54f1da7c39f3c19cf4aad40c4831dc483ed73c1 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105


int value;

/* ERRORS */
typedef;
typedef a =;
typedef b = while;
typedef c = 0;
typedef d = value;
typedef e = value while;
typedef f = int#[while];
typedef g = int:typedef;
typedef h = value:;

typedef arr = int#[3];


// try to use these corrupt typedefs
var a x1 = 1;
var b x2 = 1;
var c x3 = 1;
var d x4 = 1;
var e x5 = 1;
var f x6 = [1, 2, 3];
var g x7 = 1;

() func() {
    x1 = x2;
    x2 = x3;
    x3 = x4;
    x4 = x5;
    x5 = x1;
    x6 = x6;
    
    x1 = 0;
    x2 = 0;
    x3 = 0;
    x4 = 0;
    x5 = 0;
    x6 = [1,2,3];
    
    arr = x6;   // ERROR
    x6 = arr;   // ERROR
    x6#[0] = 1;
    
    int z1 = x1;
    int z2 = x2;
    int z3 = x3;
    int z4 = x4;
    int z5 = x5;
    int#[2] z6 = x6;
    int z7 = x7;
}

namespace Good {
    typedef here[T] = T^;  // the type parameter should not be accessible from outside the type
    int dostuff(Good[T] this) { // this is allowed
        Broken[T] loophole;
        loophole->dostuff(); // "Broken" should be broken type, so no need to report an error here
        return 0;
    }
}

() good() {
    Good[int] xx;
    xx->dostuff();
}


namespace NestTest {
    typedef here[T] = (T^, Inside[T]);

    namespace Inside {
        typedef here[T] = T^;
        int work(Inside[T] this);
    }
}

namespace BadNestTest {
    typedef here[T] = (T^, Inside[T]);

    namespace Inside {
        typedef here[U] = U^;
        int work(Inside[T] this); // ERROR type parameter from other type may not be accessed
    }
}


namespace Broken {
    typedef here[T] = T^;
    int dostuff(Broken[Good:T] this); // ERROR namespace qualified type parameters make no sense
}


() morebroken() {
    // The error about the broken function should appear
    // at the function definition and not here.
    Broken[int] xx;
    xx->dostuff();
    
    /* ERRORS */
    byte#[;} data;
    !byte#[3]^ dataptr = @data;
}