Skip to content

Commit 848cdb7

Browse files
authored
parser: fix vls mode strut mut keyword (fix #25548) (#25551)
1 parent 0db62d5 commit 848cdb7

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

‎vlib/v/parser/struct.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
132132
}
133133
p.check(.lcbr)
134134
// if p.is_vls && p.tok.kind == .key_struct { // p.tok.is_key() {
135-
if p.is_vls && p.tok.is_key() {
135+
if p.is_vls && p.tok.is_key() && p.tok.kind != .key_mut {
136136
// End parsing after `struct Foo {` in vls mode to avoid lots of junk errors
137137
// If next token after { is a key, the struct wasn't finished
138138
p.error('expected `}` to finish a struct definition')
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os
2+
import term
3+
import v.util.diff
4+
5+
const vroot = os.real_path(@VMODROOT)
6+
const tmp_dir = os.real_path(os.temp_dir())
7+
8+
const text_file = os.join_path(vroot, 'vlib', 'v', 'tests', 'vls', 'struct_text.vv')
9+
10+
fn testsuite_begin() {
11+
eprintln('testsuite_begin, text_file = ${text_file}')
12+
}
13+
14+
fn testsuite_end() {
15+
}
16+
17+
struct TestData {
18+
cmd string
19+
output string
20+
}
21+
22+
const test_data = [
23+
TestData{
24+
cmd: 'v -check -vls-mode ${os.quoted_path(text_file)}'
25+
output: '' // for a struct with `mut:` in it, should report no error
26+
},
27+
]
28+
29+
fn test_main() {
30+
mut total_errors := 0
31+
32+
for t in test_data {
33+
res := os.execute(t.cmd)
34+
if res.exit_code < 0 {
35+
println('fail execute ${t.cmd}')
36+
panic(res.output)
37+
}
38+
res_output := $if windows {
39+
res.output.replace('\r\n', '\n')
40+
} $else {
41+
res.output
42+
}
43+
if t.output != res_output {
44+
println('${term.red('FAIL')} ${t.cmd}')
45+
if diff_ := diff.compare_text(t.output, res_output) {
46+
println(term.header('difference:', '-'))
47+
println(diff_)
48+
} else {
49+
println(term.header('expected:', '-'))
50+
println(t.output)
51+
println(term.header('found:', '-'))
52+
println(res_output)
53+
}
54+
println(term.h_divider('-'))
55+
total_errors++
56+
} else {
57+
println('${term.green('OK ')} ${t.cmd}')
58+
}
59+
}
60+
assert total_errors == 0
61+
}

‎vlib/v/tests/vls/struct_text.vv‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module main
2+
3+
struct MyS {
4+
mut:
5+
a int
6+
b string
7+
}

0 commit comments

Comments
 (0)