Skip to content

Commit

Permalink
fix: exhaustiveness on types from other modules
Browse files Browse the repository at this point in the history
  • Loading branch information
rvcas committed Aug 1, 2023
1 parent 9420fd0 commit 5ce73a3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
4 changes: 4 additions & 0 deletions crates/aiken-lang/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
);

// Void
prelude
.types_constructors
.insert(VOID.to_string(), vec![VOID.to_string()]);

prelude.values.insert(
VOID.to_string(),
ValueConstructor::public(
Expand Down
2 changes: 1 addition & 1 deletion crates/aiken-lang/src/tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ fn expect_sugar_incorrect_type() {
"#;

assert!(matches!(
dbg!(check(parse(source_code))),
check(parse(source_code)),
Err((_, Error::CouldNotUnify { .. }))
))
}
Expand Down
9 changes: 4 additions & 5 deletions crates/aiken-lang/src/tipo/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,12 +1470,11 @@ impl<'a> Environment<'a> {

let missing_patterns = matrix.collect_missing_patterns(1).flatten();

for missing in &missing_patterns {
dbg!(missing);
}

if !missing_patterns.is_empty() {
let unmatched = missing_patterns.into_iter().map(|p| p.pretty()).collect();
let unmatched = missing_patterns
.into_iter()
.map(|pattern| pattern.pretty())
.collect();

return Err(Error::NotExhaustivePatternMatch {
location,
Expand Down
25 changes: 18 additions & 7 deletions crates/aiken-lang/src/tipo/exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,29 +566,40 @@ pub(super) fn simplify(
ast::Pattern::Constructor {
name,
arguments,
module,
location,
tipo,
with_spread,
module,
..
} => {
let (type_name, arity) = match tipo.deref() {
let (type_module, type_name, arity) = match tipo.deref() {
tipo::Type::App {
name: type_name, ..
} => (type_name, 0),
name: type_name,
module,
..
} => (module, type_name, 0),
tipo::Type::Fn { ret, args, .. } => match ret.deref() {
tipo::Type::App {
name: type_name, ..
} => (type_name, args.len()),
name: type_name,
module,
..
} => (module, type_name, args.len()),
_ => {
unreachable!("ret should be a Type::App")
}
},
_ => unreachable!("tipo should be a Type::App"),
};

let module_opt = if type_module.is_empty() || environment.current_module == type_module
{
None
} else {
Some(type_module.clone())
};

let constructors = environment
.get_constructors_for_type(module, type_name, *location)?
.get_constructors_for_type(&module_opt, type_name, *location)?
.clone();

let mut alts = Vec::new();
Expand Down

0 comments on commit 5ce73a3

Please sign in to comment.