fix: exhaustiveness on types from other modules

This commit is contained in:
rvcas 2023-07-31 13:59:30 -04:00 committed by Lucas
parent 7e531d0da1
commit a6b230aad4
4 changed files with 27 additions and 13 deletions

View File

@ -290,6 +290,10 @@ pub fn prelude(id_gen: &IdGenerator) -> TypeInfo {
); );
// Void // Void
prelude
.types_constructors
.insert(VOID.to_string(), vec![VOID.to_string()]);
prelude.values.insert( prelude.values.insert(
VOID.to_string(), VOID.to_string(),
ValueConstructor::public( ValueConstructor::public(

View File

@ -176,7 +176,7 @@ fn expect_sugar_incorrect_type() {
"#; "#;
assert!(matches!( assert!(matches!(
dbg!(check(parse(source_code))), check(parse(source_code)),
Err((_, Error::CouldNotUnify { .. })) Err((_, Error::CouldNotUnify { .. }))
)) ))
} }

View File

@ -1470,12 +1470,11 @@ impl<'a> Environment<'a> {
let missing_patterns = matrix.collect_missing_patterns(1).flatten(); let missing_patterns = matrix.collect_missing_patterns(1).flatten();
for missing in &missing_patterns {
dbg!(missing);
}
if !missing_patterns.is_empty() { 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 { return Err(Error::NotExhaustivePatternMatch {
location, location,

View File

@ -566,20 +566,24 @@ pub(super) fn simplify(
ast::Pattern::Constructor { ast::Pattern::Constructor {
name, name,
arguments, arguments,
module,
location, location,
tipo, tipo,
with_spread, with_spread,
module,
.. ..
} => { } => {
let (type_name, arity) = match tipo.deref() { let (type_module, type_name, arity) = match tipo.deref() {
tipo::Type::App { tipo::Type::App {
name: type_name, .. name: type_name,
} => (type_name, 0), module,
..
} => (module, type_name, 0),
tipo::Type::Fn { ret, args, .. } => match ret.deref() { tipo::Type::Fn { ret, args, .. } => match ret.deref() {
tipo::Type::App { tipo::Type::App {
name: type_name, .. name: type_name,
} => (type_name, args.len()), module,
..
} => (module, type_name, args.len()),
_ => { _ => {
unreachable!("ret should be a Type::App") unreachable!("ret should be a Type::App")
} }
@ -587,8 +591,15 @@ pub(super) fn simplify(
_ => unreachable!("tipo 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 let constructors = environment
.get_constructors_for_type(module, type_name, *location)? .get_constructors_for_type(&module_opt, type_name, *location)?
.clone(); .clone();
let mut alts = Vec::new(); let mut alts = Vec::new();