1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ast: add elem_type_pos to ChanInit (#14873)

This commit is contained in:
yuyi 2022-06-28 13:30:02 +08:00 committed by GitHub
parent 09630dd0bc
commit 42df154399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 5 deletions

View File

@ -1272,6 +1272,7 @@ pub mut:
pub struct ChanInit { pub struct ChanInit {
pub: pub:
pos token.Pos pos token.Pos
elem_type_pos token.Pos
has_cap bool has_cap bool
pub mut: pub mut:
cap_expr Expr cap_expr Expr

View File

@ -3529,7 +3529,7 @@ pub fn (mut c Checker) chan_init(mut node ast.ChanInit) ast.Type {
if node.elem_type != 0 { if node.elem_type != 0 {
elem_sym := c.table.sym(node.elem_type) elem_sym := c.table.sym(node.elem_type)
if elem_sym.kind == .placeholder { 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 { if node.has_cap {

View File

@ -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() { 1 | fn main() {
2 | _ := chan NonExistingType{} 2 | _ := chan NonExistingType{}
| ~~~~~~~~~~~~~~~~~~~~~~ | ~~~~~~~~~~~~~~~
3 | } 3 | }

View File

@ -2238,7 +2238,9 @@ pub fn (mut p Parser) name_expr() ast.Expr {
if p.tok.lit == 'chan' { if p.tok.lit == 'chan' {
first_pos := p.tok.pos() first_pos := p.tok.pos()
mut last_pos := first_pos mut last_pos := first_pos
mut elem_type_pos := p.peek_tok.pos()
chan_type := p.parse_chan_type() chan_type := p.parse_chan_type()
elem_type_pos = elem_type_pos.extend(p.prev_tok.pos())
mut has_cap := false mut has_cap := false
mut cap_expr := ast.empty_expr() mut cap_expr := ast.empty_expr()
p.check(.lcbr) p.check(.lcbr)
@ -2265,6 +2267,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
} }
return ast.ChanInit{ return ast.ChanInit{
pos: first_pos.extend(last_pos) pos: first_pos.extend(last_pos)
elem_type_pos: elem_type_pos
has_cap: has_cap has_cap: has_cap
cap_expr: cap_expr cap_expr: cap_expr
typ: chan_type typ: chan_type