# # Test .slul source file with invalid statements # # Copyright © 2022-2024 Samuel Lidén Borell # # 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() { }