# # Test of function calls (negative tests) # # Copyright © 2022-2023 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_funccalls() { # ERROR .5: error: Too many arguments to function f_void(1) # ERROR .5: error: Too few arguments to function f_int_void() # ERROR .18: error: Trailing comma not allowed in parameter list f_int_void(1,) # ERROR +2.5: error: Too few arguments to function # ERROR .22: error: Trailing comma not allowed in parameter list f_intbool_void(1,) # ERROR .17: error: Parameter not found f_int_void(.y=123) # ERROR .19: error: Target type is not an type that can take a "none" value f_int_void(.x=none) # ERROR .29: error: Parameter not found f_intbool_void(.x=123, .other=false) # ERROR .21: error: Parameters come in the wrong order f_intbool_void(.b=true, .x=123) # ERROR .5: error: Too many arguments to function f_intbool_void(.x=123, .b=true, .b=false) # ERROR .26: error: Parameter not found f_intbool_void(123, .a=true) # ERROR .26: error: Parameters come in the wrong order f_intbool_void(123, .x=true) } func StructType.do_stuff(int x) { } func bad_method_expr() { var StructType st = (.x=123, .b=true) StructType st2 = (.x=456, .b=false) st.do_stuff(123) # ERROR +2.8: error: Field "do_stuff" does not exist # ERROR .23: error: Field "do_stuff" does not exist st.do_stuff = st2.do_stuff # ERROR .8: error: Too few arguments to function st.do_stuff() # ERROR .8: error: Too many arguments to function st.do_stuff(123, 456) # ERROR .17: error: Incompatible types st.do_stuff(true) } func use_dupl_funcs() { f_dupl(123) FuncObj fo = .duplinit() fo.dupl1() } func f_void() { } func f_int_void(int x) { } func f_bool_void(bool b) { } func f_intbool_void(int x, bool b) { } func f_bool() -> bool { return true } func f_int_bool(int x) -> bool { return true } func f_bool_bool(bool b) -> bool { return true } func f_intbool_bool(int x, bool b) -> bool { return true } # ERROR .6: <-- other definition: f_dupl func f_dupl(int x) {} # ERROR .6: error: Identifier already in use func f_dupl(int x) {} type FuncObj = struct { } type FuncObj2 = struct { int x } func .duplinit() -> FuncObj { return () } # ERROR .7: error: Identifier already in use func .duplinit() -> FuncObj { return () } # ERROR .14: <-- other definition: dupl1 func FuncObj.dupl1() { } # ERROR .14: error: Identifier already in use func FuncObj.dupl1() { } func FuncObj2.bad_this_access() -> int { # FIXME this gives the wrong error (".17: error: Operator excepted here") #this.x = true # ERROR .10: error: Field "y" does not exist this.y = 123 # ERROR .17: error: Field "y" does not exist return this.y } # TODO forbid usage of the same name as both a field and a method #type FieldAndMethod = struct { # int f #} #func FieldAndMethod.f() -> int { return 123 } type EnumMethods = enum { # ERROR .5: <-- other definition: red red blue } # ERROR .18: error: Identifier already in use func EnumMethods.red() -> int { return 123 }