From 42df1543993593b414a183a53de4e52264d5f3d0 Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 28 Jun 2022 13:30:02 +0800 Subject: [PATCH] ast: add elem_type_pos to ChanInit (#14873) --- vlib/v/ast/ast.v | 5 +++-- vlib/v/checker/checker.v | 2 +- vlib/v/checker/tests/chan_elem_type_unknown.out | 4 ++-- vlib/v/parser/parser.v | 3 +++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 9f1e191380..5b2d122f6c 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -1271,8 +1271,9 @@ pub mut: pub struct ChanInit { pub: - pos token.Pos - has_cap bool + pos token.Pos + elem_type_pos token.Pos + has_cap bool pub mut: cap_expr Expr typ Type diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index c3a015ddbb..a9cabea072 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3529,7 +3529,7 @@ pub fn (mut c Checker) chan_init(mut node ast.ChanInit) ast.Type { if node.elem_type != 0 { elem_sym := c.table.sym(node.elem_type) if elem_sym.kind == .placeholder { - c.error('unknown type `$elem_sym.name`', node.pos) + c.error('unknown type `$elem_sym.name`', node.elem_type_pos) } } if node.has_cap { diff --git a/vlib/v/checker/tests/chan_elem_type_unknown.out b/vlib/v/checker/tests/chan_elem_type_unknown.out index 5fa982abab..89ef9cfda5 100644 --- a/vlib/v/checker/tests/chan_elem_type_unknown.out +++ b/vlib/v/checker/tests/chan_elem_type_unknown.out @@ -1,5 +1,5 @@ -vlib/v/checker/tests/chan_elem_type_unknown.vv:2:7: error: unknown type `NonExistingType` +vlib/v/checker/tests/chan_elem_type_unknown.vv:2:12: error: unknown type `NonExistingType` 1 | fn main() { 2 | _ := chan NonExistingType{} - | ~~~~~~~~~~~~~~~~~~~~~~ + | ~~~~~~~~~~~~~~~ 3 | } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index ac07635eaf..1792de0076 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -2238,7 +2238,9 @@ pub fn (mut p Parser) name_expr() ast.Expr { if p.tok.lit == 'chan' { first_pos := p.tok.pos() mut last_pos := first_pos + mut elem_type_pos := p.peek_tok.pos() chan_type := p.parse_chan_type() + elem_type_pos = elem_type_pos.extend(p.prev_tok.pos()) mut has_cap := false mut cap_expr := ast.empty_expr() p.check(.lcbr) @@ -2265,6 +2267,7 @@ pub fn (mut p Parser) name_expr() ast.Expr { } return ast.ChanInit{ pos: first_pos.extend(last_pos) + elem_type_pos: elem_type_pos has_cap: has_cap cap_expr: cap_expr typ: chan_type