diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index e6e0909e14..a165616197 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -182,7 +182,7 @@ fn (mut p Parser) parse_thread_type() ast.Type { if is_opt { 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() if is_opt { mut ret_type := ast.void_type @@ -196,12 +196,21 @@ fn (mut p Parser) parse_thread_type() ast.Type { if !is_opt { p.next() } - ret_type := p.parse_type() - idx := p.table.find_or_register_thread(ret_type) - if ret_type.has_flag(.generic) { - return ast.new_type(idx).set_flag(.generic) + 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) + if ret_type.has_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 { diff --git a/vlib/v/tests/parse_thread_type_test.v b/vlib/v/tests/parse_thread_type_test.v new file mode 100644 index 0000000000..9d754b02b6 --- /dev/null +++ b/vlib/v/tests/parse_thread_type_test.v @@ -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 +}