Pattern guards for functions and switch statements (#339)
* Add case guards to parser * Add pattern guards to infer types and fcode generation * Add functions guards * Add test for patterns guards * Update docs * Update CHANGELOG.md * Remove stateful context from Env for guards * Elaborate on guards * Add failing test for stateful pattern guards * Implement multiple guards * Fix tests * Disable aevm related tests * Split the sentence before if and otherwise * Fix type in docs * Implement multiple exprs in the same guard * Fix pretty printing * Change tests to include multiple guards * Add test for non-boolean guards * Desugar clauses with guards * Fix incomplete patterns bug * Fix docs * Compile to icode when no guards are used * Revert "Disable aevm related tests" This reverts commit e828099bd97dffe11438f2e48f3a92ce3641e85b.
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
contract C =
|
||||
type state = int
|
||||
|
||||
entrypoint init(x) | "y" = 1
|
||||
@@ -0,0 +1,19 @@
|
||||
include "List.aes"
|
||||
|
||||
contract C =
|
||||
type state = int
|
||||
|
||||
entrypoint init() = f([1, 2, 3, 4])
|
||||
|
||||
function
|
||||
f(x::[])
|
||||
| x > 1, x < 10 = 1
|
||||
| x < 1 = 9
|
||||
f(x::y::[]) = 2
|
||||
f(x::y::z) = switch(z)
|
||||
[] => 4
|
||||
a::[]
|
||||
| a > 10, a < 20 => 5
|
||||
| a > 5 => 8
|
||||
b | List.length(b) > 5 => 6
|
||||
c => 7
|
||||
@@ -0,0 +1,10 @@
|
||||
contract C =
|
||||
type state = int
|
||||
|
||||
entrypoint init() = f(4)
|
||||
|
||||
function
|
||||
f(x) | x > 0 = 1
|
||||
f(x) | g(x) = 2
|
||||
|
||||
stateful function g(x) = x < 0
|
||||
Reference in New Issue
Block a user