From 56d62a6e6fb67404ea0bb8384a8d51aebc33c682 Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 5 Jul 2022 21:29:54 +0800 Subject: [PATCH] checker: check undefined ident in reference selector (#14949) --- vlib/v/checker/checker.v | 1 + vlib/v/checker/tests/undefined_ident_in_ref_selector.out | 6 ++++++ vlib/v/checker/tests/undefined_ident_in_ref_selector.vv | 7 +++++++ 3 files changed, 14 insertions(+) create mode 100644 vlib/v/checker/tests/undefined_ident_in_ref_selector.out create mode 100644 vlib/v/checker/tests/undefined_ident_in_ref_selector.vv 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 +}