diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 010db9a888..8ef95c0778 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1124,6 +1124,7 @@ pub fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { // This means that the field has an undefined type. // This error was handled before. // c.error('`void` type has no fields', node.pos) + node.expr_type = ast.void_type return ast.void_type } node.expr_type = typ diff --git a/vlib/v/checker/tests/undefined_ident_in_ref_selector.out b/vlib/v/checker/tests/undefined_ident_in_ref_selector.out new file mode 100644 index 0000000000..d6f7c95f4e --- /dev/null +++ b/vlib/v/checker/tests/undefined_ident_in_ref_selector.out @@ -0,0 +1,6 @@ +vlib/v/checker/tests/undefined_ident_in_ref_selector.vv:6:10: error: undefined ident: `line` + 4 | + 5 | fn read() int { + 6 | return &line.len + | ~~~~ + 7 | } diff --git a/vlib/v/checker/tests/undefined_ident_in_ref_selector.vv b/vlib/v/checker/tests/undefined_ident_in_ref_selector.vv new file mode 100644 index 0000000000..73081c65c2 --- /dev/null +++ b/vlib/v/checker/tests/undefined_ident_in_ref_selector.vv @@ -0,0 +1,7 @@ +module main + +fn main() {} + +fn read() int { + return &line.len +}