mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
deal with aliases around number types
This commit is contained in:
parent
99a879d795
commit
fb37d925dc
2 changed files with 22 additions and 11 deletions
|
@ -12,8 +12,8 @@ pub enum NumericRange {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NumericRange {
|
impl NumericRange {
|
||||||
pub fn contains_symbol(&self, symbol: Symbol) -> bool {
|
pub fn contains_symbol(&self, symbol: Symbol) -> Option<bool> {
|
||||||
match symbol {
|
let contains = match symbol {
|
||||||
Symbol::NUM_I8 => self.contains_int_width(IntWidth::I8),
|
Symbol::NUM_I8 => self.contains_int_width(IntWidth::I8),
|
||||||
Symbol::NUM_U8 => self.contains_int_width(IntWidth::U8),
|
Symbol::NUM_U8 => self.contains_int_width(IntWidth::U8),
|
||||||
Symbol::NUM_I16 => self.contains_int_width(IntWidth::I16),
|
Symbol::NUM_I16 => self.contains_int_width(IntWidth::I16),
|
||||||
|
@ -35,8 +35,12 @@ impl NumericRange {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => unreachable!("weird number symbol {:?}", symbol),
|
_ => {
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(contains)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn contains_float_width(&self, _width: FloatWidth) -> bool {
|
fn contains_float_width(&self, _width: FloatWidth) -> bool {
|
||||||
|
|
|
@ -452,8 +452,13 @@ fn check_valid_range(subs: &mut Subs, var: Variable, range: NumericRange) -> Out
|
||||||
let content = subs.get_content_without_compacting(var);
|
let content = subs.get_content_without_compacting(var);
|
||||||
|
|
||||||
match content {
|
match content {
|
||||||
Content::Alias(symbol, _, _, _) => {
|
&Content::Alias(symbol, _, actual, _) => {
|
||||||
if !range.contains_symbol(*symbol) {
|
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 {
|
let outcome = Outcome {
|
||||||
mismatches: vec![Mismatch::TypeNotInRange],
|
mismatches: vec![Mismatch::TypeNotInRange],
|
||||||
must_implement_ability: Default::default(),
|
must_implement_ability: Default::default(),
|
||||||
|
@ -461,6 +466,8 @@ fn check_valid_range(subs: &mut Subs, var: Variable, range: NumericRange) -> Out
|
||||||
|
|
||||||
return outcome;
|
return outcome;
|
||||||
}
|
}
|
||||||
|
Some(true) => { /* fall through */ }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Content::RangedNumber(_, _) => {
|
Content::RangedNumber(_, _) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue