bakpakin / Fennel

Lua Lisp Language
https://fennel-lang.org
MIT License
2.45k stars 126 forks source link

Test that pattern matches before destructuring #346

Closed mrichards42 closed 3 years ago

mrichards42 commented 3 years ago

This patch fixes a bug where the where clause in match binds values (including destructuring table patterns) before testing that the pattern actually matches.

Without this patch, the included test errors.

A minimal example:

>> (match nil [x y z] :table _ :not-a-table)
"not-a-table"

>> (match nil (where [x y z] (not= nil x)) :table _ :not-a-table)
runtime error: attempt to index local '_0_0' (a nil value)
technomancy commented 3 years ago

Great find again; thanks.