diff --git a/compiler/types/src/num.rs b/compiler/types/src/num.rs index c9425371df..725ff00fbe 100644 --- a/compiler/types/src/num.rs +++ b/compiler/types/src/num.rs @@ -12,8 +12,8 @@ pub enum NumericRange { } impl NumericRange { - pub fn contains_symbol(&self, symbol: Symbol) -> bool { - match symbol { + pub fn contains_symbol(&self, symbol: Symbol) -> Option { + let contains = match symbol { Symbol::NUM_I8 => self.contains_int_width(IntWidth::I8), Symbol::NUM_U8 => self.contains_int_width(IntWidth::U8), Symbol::NUM_I16 => self.contains_int_width(IntWidth::I16), @@ -35,8 +35,12 @@ impl NumericRange { true } - _ => unreachable!("weird number symbol {:?}", symbol), - } + _ => { + return None; + } + }; + + Some(contains) } fn contains_float_width(&self, _width: FloatWidth) -> bool { diff --git a/compiler/unify/src/unify.rs b/compiler/unify/src/unify.rs index 180e767e01..055cd24383 100644 --- a/compiler/unify/src/unify.rs +++ b/compiler/unify/src/unify.rs @@ -452,14 +452,21 @@ fn check_valid_range(subs: &mut Subs, var: Variable, range: NumericRange) -> Out let content = subs.get_content_without_compacting(var); match content { - Content::Alias(symbol, _, _, _) => { - if !range.contains_symbol(*symbol) { - let outcome = Outcome { - mismatches: vec![Mismatch::TypeNotInRange], - must_implement_ability: Default::default(), - }; + &Content::Alias(symbol, _, actual, _) => { + match range.contains_symbol(symbol) { + None => { + // symbol not recognized; go into the alias + return check_valid_range(subs, actual, range); + } + Some(false) => { + let outcome = Outcome { + mismatches: vec![Mismatch::TypeNotInRange], + must_implement_ability: Default::default(), + }; - return outcome; + return outcome; + } + Some(true) => { /* fall through */ } } }