V: Match must be exhaustive

Created on 4 Apr 2020  路  5Comments  路  Source: vlang/v

V version: V 0.1.26 abd0686.abd0686
OS: MacOS

What did you do?

// enums.v 
enum Colour { red green blue }
fn main() {
  mut col := Colour.red
  match col {
    .red    { println("Red") }
    .green  { println("Green") }
    .blue   { println("Blue") }
  }
}

% v enums.v

What did you expect to see?
Red

What did you see instead?
enums.v:9:0: error: match must be exhaustive

Bug

Most helpful comment

Well that's the thing. If all vals are checked, else should not be needed.

All 5 comments

@planmac You need to add an empty else condition inside the match statement for it to work.

Well that's the thing. If all vals are checked, else should not be needed.

Thats what I would have expected - if all the vals are included then 'else' should not be needed, otherwise the compile check for exhaustive is of no use whatsoever!

Should this part of checking moved to checker.v? @medvednikov

Why did you close this @danieldaeschle ?

It's not fixed yet.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shouji-kazuo picture shouji-kazuo  路  3Comments

taojy123 picture taojy123  路  3Comments

radare picture radare  路  3Comments

XVilka picture XVilka  路  3Comments

aurora picture aurora  路  3Comments