mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: disallow method calls with invalid expressions (#15337)
This commit is contained in:
parent
9b88feccad
commit
a6026fd505
@ -1113,6 +1113,10 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
|
||||
|
||||
pub fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
||||
left_type := c.expr(node.left)
|
||||
if left_type == ast.void_type {
|
||||
c.error('cannot call a method using an invalid expression', node.pos)
|
||||
return ast.void_type
|
||||
}
|
||||
c.expected_type = left_type
|
||||
mut is_generic := left_type.has_flag(.generic)
|
||||
node.left_type = left_type
|
||||
|
6
vlib/v/checker/tests/void_method_call.out
Normal file
6
vlib/v/checker/tests/void_method_call.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/void_method_call.vv:5:17: error: cannot call a method using an invalid expression
|
||||
3 |
|
||||
4 | fn main() {
|
||||
5 | simple_fn().method()
|
||||
| ~~~~~~~~
|
||||
6 | }
|
6
vlib/v/checker/tests/void_method_call.vv
Normal file
6
vlib/v/checker/tests/void_method_call.vv
Normal file
@ -0,0 +1,6 @@
|
||||
fn simple_fn() {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
simple_fn().method()
|
||||
}
|
Loading…
Reference in New Issue
Block a user