koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.23k stars 157 forks source link

[BUG] Error when using identifier in pattern matching #37

Closed Pauan closed 6 years ago

Pauan commented 7 years ago

This code:

match (1) { a -> a }

Fails with this error:

Backend.JavaScript.FromCore.genMatch: no branch in match statement: [_x0]
Pauan commented 7 years ago

I did a lot of debugging, and I found the source of this bug:

  1. Because a variable is not a constructor, conNamess is empty.

  2. So when it calls visitBranches, the cases is empty.

  3. This causes it to print a warning and completely discard all of the branches, so the end result is that the match expression gets rewritten to match (1) {}

b-studios commented 6 years ago

I tried to reproduce the bug in the current version of Koka, but the above example successfully evaluates to 1.