You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if expression with multi-statement branch fails to compile when the penultimate statement has a variable reference unless a statement terminator ';' is present. vfmt removes the ';'
Reproduction Steps
compile this:
module main
fn if_expt(this int) (string, int) {
inc := 1
mut count := 0
thing := if this in [0,1,2] {
count += 1
'0..2'
} else if this in [3,4,5] {
count += inc; // fails when no end-of-statement ';' which is removed by vfmt
'3..5'
} else {
'not 0..5'
}
return thing, count
}
fn main() {
println(if_expt(1)) // expect ('0..2', 1)
println(if_expt(4)) // expect ('3..5', 1)
println(if_expt(7)) // expect ('not 0..5', 0)
}
then run it through vmt and compile again, vfmt removes the ';' and the compiler complains:
compiler_bugs/main.v:9:12: error: only `c`, `r`, `js` are recognized string prefixes, but you tried to use `inc`
7 | '0..2'
8 | } else if this in [3,4,5] {
9 | count += inc // fails when no end-of-statement ';' which is removed by vfmt
| ~~~
10 | '3..5'
11 | } else {
Expected Behavior
It should either compile or vfmt should not remove ';'
Current Behavior
get compiler error:
compiler_bugs/main.v:9:12: error: only `c`, `r`, `js` are recognized string prefixes, but you tried to use `inc`
7 | '0..2'
8 | } else if this in [3,4,5] {
9 | count += inc // fails when no end-of-statement ';' which is removed by vfmt
| ~~~
10 | '3..5'
11 | } else {
Describe the bug
if expression with multi-statement branch fails to compile when the penultimate statement has a variable reference unless a statement terminator ';' is present. vfmt removes the ';'
Reproduction Steps
compile this:
then run it through vmt and compile again, vfmt removes the ';' and the compiler complains:
Expected Behavior
It should either compile or vfmt should not remove ';'
Current Behavior
get compiler error:
Possible Solution
wrap the statement with vfmt off/on
Additional Information/Context
No response
V version
V 0.4.10 b76b1ee
Environment details (OS name and version, etc.)
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.