aboutsummaryrefslogtreecommitdiffhomepage
path: root/errortest/mainapp/funcchk.slul
blob: 7c55d8dbd28716af80f5f613c9ca8f51ea6f20d2 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357

#
# Test .slul source file with invalid statements
#
# Copyright © 2022-2024 Samuel Lidén Borell <samuel@kodafritt.se>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

func bad_statements()
{
    int i = 111
    # ERROR .13: warning: Expression is always true
    if true or true { }
    # ERROR .19: warning: Expression is always false
    else if false and false { }
    # ERROR .16: warning: Expression is always true
    while true or false { }
    # ERROR .23: warning: Expression is always false
    do { } while true and false
    # ERROR .12: warning: "assert true" is meaningless
    assert true
    # ERROR .17: warning: Expression is always false
    assert true and not true
    # ERROR .59: warning: Expression is always true
    if i == 111 and (not i < 111) and (i >= 111 or false) and not i == -111 { }

    # Bad declarations
    {
        # ERROR .12: error: Incorrect syntax. Expected a type here.
        [1]not x
    }
    {
        # ERROR .18: error: Incomplete expression
        int i1 = if
    }
    {
        # FIXME error message is wrong (should be something like "1 is not assignable or similar")
        # ERROR .18: error: Type of expression is not clear
        int i2 = 1=2
    }
    {
        # FIXME error message is wrong (should be something like "left side of comparison must have a clear type")
        # ERROR +2.18: error: Type of expression is not clear
        # ERROR .19: error: Incompatible types
        int i3 = 1==2
    }

    if false {
        # ERROR .12: error: Incomplete expression
        if return
        # ERROR .11: error: Incomplete expression
        if
        if true { }
        # ERROR .15: error: Incomplete expression
        while return
        # ERROR .16: error: Incomplete expression
        assert return
        # ERROR .14: error: Expected an identifier here
        goto if
        # ERROR .13: error: Expected an identifier here
        goto
        if true { }
    }

    # ERROR .17: error: Expected { before statement block
    while false }
    # ERROR .16: error: Expected { before statement block
    while false
    }
    # ERROR .10: error: Incomplete expression
    while
    int dummy
    # ERROR +2.8: error: Too many }
    # ERROR .8: error: Missing {
    do }
    # ERROR .7: error: Missing {
    do
    # ERROR .5: error: Too many }
    }

    # ERROR .5: warning: Unreachable statements after return
    return
    stmt_badgoto()

    # ERROR .5: error: Identifier 'non_existent_funcchk1' does not exist
    non_existent_funcchk1()
    # It seems that this one has to come last
    # ERROR .26: error: Incomplete expression
    if true { assert not }
}

func stmt_badgoto()
{
    # ERROR .10: error: Expected an identifier here
    goto return
}

func stmt_missing_expr()
{
    # ERROR .22: error: Incomplete expression
    if true { assert }
    # ERROR .18: error: Incomplete expression
    if true { if }
    # ERROR .21: error: Incomplete expression
    if true { while }
    # ERROR .18: error: Missing {
    if true { do }
    # ERROR .19: error: Incorrect syntax. Expected a type here.
    if true { for }
    # ERROR .23: error: Expected an identifier here
    if true { for int }
    # ERROR .28: error: Incomplete expression
    if true { for int x in }
}

# Needs a separate function because the parser "corrects" the "}" to a "{"
func stmt_missing_expr2()
{
    # ERROR .24: error: Expected "in" after loop variable
    if true { for int x }
    # ERROR +2.1: error: Missing } after end of function
}

func stmt_elsewithoutrcurly(int x)
{
    var int y
    if x == 1 {
        y = 11
    # ERROR .5: error: Missing "}" before else
    else {
        y = 22
    }

    if x == 3 {
        y = 33
        while true { }
    # ERROR .5: error: Missing "}" before else
    else {
        y = 44
    }
}

func funcchk_for_dummy() { }

func funcchk_for_arrays()
{
    # ERROR +2.19: error: Incompatible types
    # ERROR .26: error: Incompatible types
    for int i in [false, true] { }
    # ERROR +2.23: error: Incompatible types
    # ERROR .32: error: Incompatible types
    for [1]int i in [[false], [true]] { }
    # ERROR .31: error: Incompatible types. Array lengths differ
    for [2]int i in [[11,22], [33]] { }

    # ERROR .9: error: This type qualifier is not allowed here
    for aliased int i in [1, 2] { }
}

func funcchk_for_broken()
{
    # ERROR +3.9: error: Type 'NotFound' does not exist
    # ERROR +2.24: error: Invalid character in number
    # ERROR .24: error: Operator expected here
    for NotFound i in 1x { }
}

func funcchk_wrong_case_order()
{
    int i = 0
    var int x = 1
    switch i {
    # ERROR +2.5: error: Repeated "case"s are not allowed
    case 1:
    default:
        x += 2
    }
    switch i {
    # ERROR +3.5: error: Repeated "case"s are not allowed
    # ERROR +2.5: error: "case" after "default:" case. "default:" must come last
    default:
    case 1:
        x += 4
    }
    switch i {
    default:
        x += 8
    # ERROR .5: error: Duplicate "default:"
    default:
        x += 16
    }
    switch i {
    default:
        x += 32
    # ERROR .5: error: "case" after "default:" case. "default:" must come last
    case 123:
        x += 32
    }
}

func funcchk_no_effect()
{
    var int a = 123

    # ERROR .7: error: Operation has no effect
    (1+2)
    # ERROR .6: error: Operation has no effect
    a+1
    # ERROR .6: error: Operation has no effect
    a==2
    # ERROR .5: error: Operation has no effect
    a
}

func funcchk_param(int i) -> bool
{
    # ERROR .12: error: Incompatible types
    return i
}

# ERROR .23: error: Expected ( after function name
func funcchk_noparams x
{
}

func funcchk_call_bad_func() -> int
{
    return funcchk_noparams()
}

func funcchk_badend()
{
    # ERROR +2.5: error: Operation has no effect
    # ERROR .5: error: Identifier 'nonexisting_funcchk_badend' does not exist
    nonexisting_funcchk_badend
# ERROR +0.1: error: Missing } after end of function
data int funcchk_badend1 = 1

func funcchk_badend2a()
{
# ERROR .2: error: Invalid start of line in function
 func funcchk_badend2b() {
}
# ERROR +0.1: error: Missing } after end of function
data int funcchk_badend2c = 1

func funcchk_badend3 ()
{
# ERROR .2: error: Final } is indented
 }
data int funcchk_badend3b = 2

func funcchk_baddecl()
{
    # ERROR .8: error: Expected an identifier here
    int
}

func funcchk_baddecl2() -> int
{
    int uninited
    # ERROR +2.11: error: Missing "=" between declaration and initial value
    # ERROR .11: error: Incomplete expression
    int i type
    # ERROR .12: error: Variable is (or might be) unassigned at this point
    return uninited
}

func funcchk_baddecl3()
{
    # ERROR .25: error: Missing "=" between declaration and initial value
    [3,1,2]int deep_arr [     # <--- missing =
        [[111,112]],
        [[211,212]],
        [[311,312]],
    ]
}

func funcchk_baddecl4()
{
    # Unconvential style, but allowed
    int a
    = 123

    # ERROR +3.5: warning: Line(s) between declaration and '='
    int b

    = 123

    # ERROR +3.5: warning: Line(s) between declaration and '='
    int c
    # x
    = 123
}

func funcchk_strangeindent()
{
    do {
        var int a = 1
        if true goto skip
    a = 2
        if true break
    a = 2
    } while true
  skip:
}

func funcchk_missingnewlines()
{
    # ERROR .11: error: Variable definition detected inside line
    int x int y
    var int z
    # ERROR .17: error: Unexpected symbol in expression
    assert true assert true
    # ERROR .17: error: Syntax error, or missing line break, before this symbol
    if true { } if true { }
    # ERROR +2.10: error: Expected { before statement block
    if true { }
    else z = 123
}

func funcchk_missingnewlines2()
{
    if true {
        var int x
        # ERROR +2.14: error: Expected { before statement block
        if true { }
        else x = 3
    }
}

func funcchk_toodeep()
{
    # ERROR .104: error: Too deep nesting of blocks
    {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
}
data bool funcchk_dummy_toodeep = false

func funcchk_end_dummy()
{
}