1
0
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:
StunxFS 2022-08-08 10:35:24 -04:00 committed by GitHub
parent 9b88feccad
commit a6026fd505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -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

View 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 | }

View File

@ -0,0 +1,6 @@
fn simple_fn() {
}
fn main() {
simple_fn().method()
}