feat: support nested void matching

This commit is contained in:
rvcas 2024-02-13 21:29:24 -05:00
parent ac0c73a56a
commit 0ccfe60072
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
4 changed files with 30 additions and 4 deletions

View File

@ -2568,10 +2568,6 @@ impl<'a> CodeGenerator<'a> {
let (_, assign) = self.clause_pattern(pattern, subject_tipo, props, then);
assign
} else {
assert!(
!subject_tipo.is_void(),
"WHY ARE YOU PATTERN MATCHING ON A NESTED VOID???"
);
match pattern {
Pattern::Int { value, .. } => {
props.complex_clause = true;
@ -2700,6 +2696,13 @@ impl<'a> CodeGenerator<'a> {
bool(),
then,
)
} else if subject_tipo.is_void() {
AirTree::clause_guard(
&props.original_subject_name,
AirTree::void(),
void(),
then,
)
} else {
let (cond, assign) =
self.clause_pattern(pattern, subject_tipo, props, then);
@ -4791,6 +4794,8 @@ impl<'a> CodeGenerator<'a> {
.force();
}
Some(term)
} else if tipo.is_void() {
Some(then.lambda("_").apply(Term::var(subject_name)))
} else {
let condition = if tipo.is_int() {
Term::equals_integer()

View File

@ -0,0 +1,7 @@
# This file was generated by Aiken
# You typically do not need to edit this file
requirements = []
packages = []
[etags]

View File

@ -0,0 +1,4 @@
name = "thing/thing"
version = "0.0.0"
license = "Apache-2.0"
description = "Aiken contracts for project 'thing/thing'"

View File

@ -0,0 +1,10 @@
pub fn wow(a: Void) -> Int {
when Some(a) is {
Some(Void) -> 42
None -> 0
}
}
test wow_1() {
wow(Void) == 42
}