Skip to content

Commit 56228f3

Browse files
authored
parser: disallow [3]!int{} (fix #26244) (#26249)
1 parent 2c5a2c8 commit 56228f3

4 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎vlib/v/parser/checks.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn (p &Parser) is_array_type() bool {
7373
if tok.kind in [.name, .amp] {
7474
return true
7575
}
76-
if tok.kind == .eof {
76+
if tok.kind in [.eof, .colon, .dot] {
7777
break
7878
}
7979
i++

‎vlib/v/parser/containers.v‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ fn (mut p Parser) array_init(is_option bool, alias_array_type ast.Type) ast.Arra
119119
last_pos = p.tok.pos()
120120
is_fixed = true
121121
has_val = true
122-
p.next()
122+
if exprs.len == 1 && p.tok.line_nr == line_nr && p.is_array_type() {
123+
p.error('fixed arrays do not support storing Result values')
124+
} else {
125+
p.next()
126+
}
123127
}
124128
if p.tok.kind == .not && p.tok.line_nr == p.prev_tok.line_nr {
125129
last_pos = p.tok.pos()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vlib/v/parser/tests/fixed_array_init_result_err.vv:1:8: error: fixed arrays do not support storing Result values
2+
1 | _ = [3]!int{}
3+
| ^
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_ = [3]!int{}

0 commit comments

Comments
 (0)