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

parser: fix improper token advancement when parsing the types of struct thread type fields(fix #19029) (#19030)

This commit is contained in:
shove 2023-08-02 00:10:52 +08:00 committed by GitHub
parent ecf8fcd45a
commit b6d6d4b037
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 6 deletions

View File

@ -182,7 +182,7 @@ fn (mut p Parser) parse_thread_type() ast.Type {
if is_opt { if is_opt {
p.next() p.next()
} }
if p.peek_tok.kind !in [.name, .key_mut, .amp, .lsbr] { if p.peek_tok.kind !in [.name, .key_pub, .key_mut, .amp, .lsbr] {
p.next() p.next()
if is_opt { if is_opt {
mut ret_type := ast.void_type mut ret_type := ast.void_type
@ -196,12 +196,21 @@ fn (mut p Parser) parse_thread_type() ast.Type {
if !is_opt { if !is_opt {
p.next() p.next()
} }
ret_type := p.parse_type() if is_opt || p.tok.kind in [.amp, .lsbr]
|| (p.tok.lit.len > 0 && p.tok.lit[0].is_capital())
|| ast.builtin_type_names_matcher.matches(p.tok.lit)
|| p.peek_tok.kind == .dot {
mut ret_type := p.parse_type()
if is_opt {
ret_type = ret_type.set_flag(.option)
}
idx := p.table.find_or_register_thread(ret_type) idx := p.table.find_or_register_thread(ret_type)
if ret_type.has_flag(.generic) { if ret_type.has_flag(.generic) {
return ast.new_type(idx).set_flag(.generic) return ast.new_type(idx).set_flag(.generic)
} }
return ast.new_type(idx) return ast.new_type(idx)
}
return ast.thread_type
} }
fn (mut p Parser) parse_multi_return_type() ast.Type { fn (mut p Parser) parse_multi_return_type() ast.Type {

View File

@ -0,0 +1,30 @@
struct Foo1 {
before_1 int
thr thread
after_1 int
after_2 int
after_3 int
}
struct Foo2 {
thr thread
a ?int
}
struct Foo3 {
thrs []thread
a []int
}
struct Foo4 {
thrs []thread int
a []int
}
fn test_parse_thread_type() {
_ = &Foo1{}
_ = &Foo2{}
_ = &Foo3{}
_ = &Foo4{}
assert true
}