From 5ce73a38288e0a70426dcc094169a93029114711 Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 31 Jul 2023 13:59:30 -0400 Subject: [PATCH] fix: exhaustiveness on types from other modules --- crates/aiken-lang/src/builtins.rs | 4 ++++ crates/aiken-lang/src/tests/check.rs | 2 +- crates/aiken-lang/src/tipo/environment.rs | 9 ++++---- crates/aiken-lang/src/tipo/exhaustive.rs | 25 ++++++++++++++++------- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/crates/aiken-lang/src/builtins.rs b/crates/aiken-lang/src/builtins.rs index 12d8622ca..39e5c9d00 100644 --- a/crates/aiken-lang/src/builtins.rs +++ b/crates/aiken-lang/src/builtins.rs @@ -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( diff --git a/crates/aiken-lang/src/tests/check.rs b/crates/aiken-lang/src/tests/check.rs index 52df87a21..df2b47ec9 100644 --- a/crates/aiken-lang/src/tests/check.rs +++ b/crates/aiken-lang/src/tests/check.rs @@ -176,7 +176,7 @@ fn expect_sugar_incorrect_type() { "#; assert!(matches!( - dbg!(check(parse(source_code))), + check(parse(source_code)), Err((_, Error::CouldNotUnify { .. })) )) } diff --git a/crates/aiken-lang/src/tipo/environment.rs b/crates/aiken-lang/src/tipo/environment.rs index 6d8c6175f..4c7f5d38c 100644 --- a/crates/aiken-lang/src/tipo/environment.rs +++ b/crates/aiken-lang/src/tipo/environment.rs @@ -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, diff --git a/crates/aiken-lang/src/tipo/exhaustive.rs b/crates/aiken-lang/src/tipo/exhaustive.rs index 0f444fb12..c149c0fcf 100644 --- a/crates/aiken-lang/src/tipo/exhaustive.rs +++ b/crates/aiken-lang/src/tipo/exhaustive.rs @@ -566,20 +566,24 @@ 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") } @@ -587,8 +591,15 @@ pub(super) fn simplify( _ => 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();