mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 05:34:11 +03:00
equal_pattern_types takes type index
This commit is contained in:
parent
c53e08f63c
commit
0990eda0cb
@ -215,6 +215,10 @@ impl Constraints {
|
||||
Index::push_new(&mut self.expectations, expected.map(Cell::new))
|
||||
}
|
||||
|
||||
pub fn push_pat_expected_type(&mut self, expected: PExpected<Type>) -> PExpectedTypeIndex {
|
||||
Index::push_new(&mut self.pattern_expectations, expected.map(Cell::new))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn push_category(&mut self, category: Category) -> Index<Category> {
|
||||
match category {
|
||||
@ -306,14 +310,11 @@ impl Constraints {
|
||||
|
||||
pub fn equal_pattern_types(
|
||||
&mut self,
|
||||
typ: Type,
|
||||
expected: PExpected<Type>,
|
||||
type_index: TypeOrVar,
|
||||
expected_index: PExpectedTypeIndex,
|
||||
category: PatternCategory,
|
||||
region: Region,
|
||||
) -> Constraint {
|
||||
let type_index = self.push_type(typ);
|
||||
let expected_index =
|
||||
Index::push_new(&mut self.pattern_expectations, expected.map(Cell::new));
|
||||
let category_index = Self::push_pattern_category(self, category);
|
||||
|
||||
Constraint::Pattern(type_index, expected_index, category_index, region)
|
||||
|
@ -238,6 +238,9 @@ pub fn constrain_pattern(
|
||||
region,
|
||||
Category::Num,
|
||||
);
|
||||
let num_type = constraints.push_type(num_type);
|
||||
|
||||
let expected = constraints.push_pat_expected_type(expected);
|
||||
|
||||
state.constraints.push(constraints.equal_pattern_types(
|
||||
num_type,
|
||||
@ -259,18 +262,19 @@ pub fn constrain_pattern(
|
||||
region,
|
||||
Category::Int,
|
||||
);
|
||||
let num_type = constraints.push_type(num_type);
|
||||
|
||||
// Link the free num var with the int var and our expectation.
|
||||
let int_type = builtins::num_int(Type::Variable(precision_var));
|
||||
|
||||
state.constraints.push({
|
||||
let type_index = constraints.push_type(num_type.clone()); // TODO check me if something breaks!
|
||||
let expected_index =
|
||||
constraints.push_expected_type(Expected::NoExpectation(int_type));
|
||||
constraints.equal_types(type_index, expected_index, Category::Int, region)
|
||||
constraints.equal_types(num_type, expected_index, Category::Int, region)
|
||||
});
|
||||
|
||||
// Also constrain the pattern against the num var, again to reuse aliases if they're present.
|
||||
let expected = constraints.push_pat_expected_type(expected);
|
||||
state.constraints.push(constraints.equal_pattern_types(
|
||||
num_type,
|
||||
expected,
|
||||
@ -294,17 +298,18 @@ pub fn constrain_pattern(
|
||||
|
||||
// Link the free num var with the float var and our expectation.
|
||||
let float_type = builtins::num_float(Type::Variable(precision_var));
|
||||
let num_type_index = constraints.push_type(num_type); // TODO check me if something breaks!
|
||||
|
||||
state.constraints.push({
|
||||
let type_index = constraints.push_type(num_type.clone()); // TODO check me if something breaks!
|
||||
let expected_index =
|
||||
constraints.push_expected_type(Expected::NoExpectation(float_type));
|
||||
constraints.equal_types(type_index, expected_index, Category::Frac, region)
|
||||
constraints.equal_types(num_type_index, expected_index, Category::Frac, region)
|
||||
});
|
||||
|
||||
// Also constrain the pattern against the num var, again to reuse aliases if they're present.
|
||||
let expected = constraints.push_pat_expected_type(expected);
|
||||
state.constraints.push(constraints.equal_pattern_types(
|
||||
num_type, // TODO check me if something breaks!
|
||||
num_type_index,
|
||||
expected,
|
||||
PatternCategory::Float,
|
||||
region,
|
||||
@ -312,8 +317,10 @@ pub fn constrain_pattern(
|
||||
}
|
||||
|
||||
StrLiteral(_) => {
|
||||
let str_type = constraints.push_type(builtins::str_type());
|
||||
let expected = constraints.push_pat_expected_type(expected);
|
||||
state.constraints.push(constraints.equal_pattern_types(
|
||||
builtins::str_type(),
|
||||
str_type,
|
||||
expected,
|
||||
PatternCategory::Str,
|
||||
region,
|
||||
@ -336,12 +343,13 @@ pub fn constrain_pattern(
|
||||
// Link the free num var with the int var and our expectation.
|
||||
let int_type = builtins::num_int(Type::Variable(precision_var));
|
||||
|
||||
let num_type_index = constraints.push_type(num_type.clone());
|
||||
|
||||
state.constraints.push({
|
||||
let type_index = constraints.push_type(num_type.clone());
|
||||
let expected_index =
|
||||
constraints.push_expected_type(Expected::NoExpectation(int_type));
|
||||
constraints.equal_types(
|
||||
type_index, // TODO check me if something breaks!
|
||||
num_type_index, // TODO check me if something breaks!
|
||||
expected_index,
|
||||
Category::Int,
|
||||
region,
|
||||
@ -349,8 +357,9 @@ pub fn constrain_pattern(
|
||||
});
|
||||
|
||||
// Also constrain the pattern against the num var, again to reuse aliases if they're present.
|
||||
let expected = constraints.push_pat_expected_type(expected);
|
||||
state.constraints.push(constraints.equal_pattern_types(
|
||||
num_type,
|
||||
num_type_index,
|
||||
expected,
|
||||
PatternCategory::Character,
|
||||
region,
|
||||
|
Loading…
Reference in New Issue
Block a user