aboutsummaryrefslogtreecommitdiffhomepage
path: root/errortest/mainapp/funccalls.slul
blob: 4510e149582b7e6b108585b0863992d0afc78c14 (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

#
# Test of function calls (negative tests)
#
# Copyright © 2022-2023 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_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 }