mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check result type method call (#15794)
This commit is contained in:
@@ -1199,6 +1199,9 @@ pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
||||
if left_type.has_flag(.optional) {
|
||||
c.error('optional type cannot be called directly', node.left.pos())
|
||||
return ast.void_type
|
||||
} else if left_type.has_flag(.result) {
|
||||
c.error('result type cannot be called directly', node.left.pos())
|
||||
return ast.void_type
|
||||
}
|
||||
if left_sym.kind in [.sum_type, .interface_] {
|
||||
if method_name == 'type_name' {
|
||||
|
||||
6
vlib/v/checker/tests/result_type_call_err.out
Normal file
6
vlib/v/checker/tests/result_type_call_err.out
Normal file
@@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/result_type_call_err.vv:12:2: error: result type cannot be called directly
|
||||
10 |
|
||||
11 | fn main() {
|
||||
12 | new_foo().foo()
|
||||
| ~~~~~~~~~
|
||||
13 | }
|
||||
13
vlib/v/checker/tests/result_type_call_err.vv
Normal file
13
vlib/v/checker/tests/result_type_call_err.vv
Normal file
@@ -0,0 +1,13 @@
|
||||
struct Foo {}
|
||||
|
||||
fn (f Foo) foo() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
fn new_foo() !Foo {
|
||||
return Foo{}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
new_foo().foo()
|
||||
}
|
||||
Reference in New Issue
Block a user