File tree Expand file tree Collapse file tree 3 files changed +61
-1
lines changed Expand file tree Collapse file tree 3 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -2277,7 +2277,7 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
2277
2277
if field := c.table.find_field (left_type_sym, method_name) {
2278
2278
field_type_sym := c.table.get_type_symbol (c.unwrap_generic (field.typ))
2279
2279
if field_type_sym.kind == .function {
2280
- // node.is_method = false
2280
+ node.is_method = false
2281
2281
node.is_field = true
2282
2282
info := field_type_sym.info as ast.FnType
2283
2283
node.return_type = info.func.return_type
@@ -2288,6 +2288,8 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
2288
2288
earg_types << targ
2289
2289
}
2290
2290
node.expected_arg_types = earg_types
2291
+ c.check_expected_arg_count (mut node, info.func) or { return info.func.return_type }
2292
+ node.is_method = true
2291
2293
return info.func.return_type
2292
2294
}
2293
2295
}
Original file line number Diff line number Diff line change
1
+ vlib/v/checker/tests/generics_struct_field_fn_args_err.vv:21:20: error: expected 0 arguments, but got 1
2
+ 19 | }
3
+ 20 | println(fun0.call())
4
+ 21 | println(fun0.call(1234))
5
+ | ~~~~
6
+ 22 | println(fun0.call(1234, 5678))
7
+ 23 |
8
+ vlib/v/checker/tests/generics_struct_field_fn_args_err.vv:22:20: error: expected 0 arguments, but got 2
9
+ 20 | println(fun0.call())
10
+ 21 | println(fun0.call(1234))
11
+ 22 | println(fun0.call(1234, 5678))
12
+ | ~~~~~~~~~~
13
+ 23 |
14
+ 24 | fun1 := Fun<fn (int) int>{
15
+ vlib/v/checker/tests/generics_struct_field_fn_args_err.vv:29:15: error: expected 1 arguments, but got 0
16
+ 27 |
17
+ 28 | println(fun1.call(42))
18
+ 29 | println(fun1.call())
19
+ | ~~~~~~
20
+ 30 | println(fun1.call(42, 43))
21
+ 31 | }
22
+ vlib/v/checker/tests/generics_struct_field_fn_args_err.vv:30:24: error: expected 1 arguments, but got 2
23
+ 28 | println(fun1.call(42))
24
+ 29 | println(fun1.call())
25
+ 30 | println(fun1.call(42, 43))
26
+ | ~~
27
+ 31 | }
Original file line number Diff line number Diff line change
1
+ fn get_int() int {
2
+ return 42
3
+ }
4
+
5
+ fn dub_int(i int) int {
6
+ return i * 2
7
+ }
8
+
9
+ struct Fun<F> {
10
+ mut:
11
+ call F
12
+ }
13
+
14
+ type FunZero = fn () int
15
+
16
+ fn main() {
17
+ fun0 := Fun<FunZero>{
18
+ call: get_int
19
+ }
20
+ println(fun0.call())
21
+ println(fun0.call(1234))
22
+ println(fun0.call(1234, 5678))
23
+
24
+ fun1 := Fun<fn (int) int>{
25
+ call: dub_int
26
+ }
27
+
28
+ println(fun1.call(42))
29
+ println(fun1.call())
30
+ println(fun1.call(42, 43))
31
+ }
You can’t perform that action at this time.
0 commit comments