From c733887c16d15addc6dd0bb456eb3a15f1b08f9e Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 26 Feb 2026 20:00:24 +0300 Subject: [PATCH] parser: fix thread variable in struct causing inconsistent expecting type declaration error (fixes #25330) --- vlib/v/parser/parse_type.v | 8 +++++--- vlib/v/tests/parse_thread_type_test.v | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index cfe40234b..a3342cd7f 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -261,12 +261,14 @@ fn (mut p Parser) parse_thread_type() ast.Type { idx := p.table.find_or_register_thread(ret_type) return ast.new_type(idx) } - is_opt := p.peek_tok.kind == .question - is_result := p.peek_tok.kind == .not + is_same_line := p.peek_tok.line_nr == p.tok.line_nr + is_opt := is_same_line && p.peek_tok.kind == .question + is_result := is_same_line && p.peek_tok.kind == .not if is_opt || is_result { p.next() } - if p.peek_tok.kind !in [.name, .key_pub, .key_mut, .amp, .lsbr] { + if p.peek_tok.line_nr > p.tok.line_nr + || p.peek_tok.kind !in [.name, .key_pub, .key_mut, .amp, .lsbr] { p.next() if is_opt { mut ret_type := ast.void_type diff --git a/vlib/v/tests/parse_thread_type_test.v b/vlib/v/tests/parse_thread_type_test.v index 9d754b02b..be68e0b03 100644 --- a/vlib/v/tests/parse_thread_type_test.v +++ b/vlib/v/tests/parse_thread_type_test.v @@ -1,3 +1,5 @@ +struct MyStruct {} + struct Foo1 { before_1 int thr thread @@ -21,10 +23,17 @@ struct Foo4 { a []int } +struct Foo5 { + // a comment + my_th thread + map []MyStruct +} + fn test_parse_thread_type() { _ = &Foo1{} _ = &Foo2{} _ = &Foo3{} _ = &Foo4{} + _ = &Foo5{} assert true } -- 2.39.5