vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.8k stars 2.16k forks source link

Inaccurate error message in match expressions #13669

Open ghost opened 2 years ago

ghost commented 2 years ago

V version: 0.2.4 36ec47c OS: ArchLinux

What did you do?

pub fn foo() {
    x := 1
    match true {
        x >  {
            y := 0
        }
        else {}
    }
}

What did you expect to see? error message like x > { is wrong

What did you see instead?

main.v:5:6: error: unexpected token `:=`, expecting `:`
    3 |     match true {
    4 |         x >  {
    5 |             y := 0
      |               ~~
    6 |         }
    7 |         else {}
felipensp commented 1 year ago

In this context the expr is being parsed without the context evaluation. However, when you complete the syntax properly, you are receive the expected error.

error: infix expr: cannot use `map[void]int` (right expression) as `int`