mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Fix type errors
This commit is contained in:
parent
fe2f2b2027
commit
28d6f30cc7
4 changed files with 41 additions and 20 deletions
|
@ -1,3 +1,5 @@
|
|||
use std::iter::FromIterator;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct VecMap<K, V> {
|
||||
keys: Vec<K>,
|
||||
|
@ -184,3 +186,15 @@ impl<K, V> ExactSizeIterator for IntoIter<K, V> {
|
|||
self.len
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: PartialEq, V> FromIterator<(K, V)> for VecMap<K, V> {
|
||||
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
|
||||
let iter = iter.into_iter();
|
||||
let size_hint = iter.size_hint();
|
||||
let mut map = VecMap::with_capacity(size_hint.1.unwrap_or(size_hint.0));
|
||||
for (k, v) in iter {
|
||||
map.insert(k, v);
|
||||
}
|
||||
map
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::iter::FromIterator;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct VecSet<T> {
|
||||
elements: Vec<T>,
|
||||
|
@ -101,6 +103,14 @@ impl<A: Ord> Extend<A> for VecSet<A> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<A: Ord> FromIterator<A> for VecSet<A> {
|
||||
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
|
||||
let mut set = VecSet::default();
|
||||
set.extend(iter);
|
||||
set
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoIterator for VecSet<T> {
|
||||
type Item = T;
|
||||
|
||||
|
|
|
@ -183,6 +183,7 @@ pub fn frontload_ability_constraints(
|
|||
signature,
|
||||
} = &member_data.typ
|
||||
{
|
||||
let signature_var = *signature_var;
|
||||
let rigids = Default::default();
|
||||
let mut env = Env {
|
||||
home,
|
||||
|
@ -195,22 +196,21 @@ pub fn frontload_ability_constraints(
|
|||
constraints,
|
||||
&mut env,
|
||||
&pattern,
|
||||
Type::Variable(member_data.signature_var),
|
||||
Type::Variable(signature_var),
|
||||
);
|
||||
|
||||
debug_assert!(env.resolutions_to_make.is_empty());
|
||||
|
||||
def_pattern_state.vars.push(member_data.signature_var);
|
||||
def_pattern_state.vars.push(signature_var);
|
||||
|
||||
let vars = &member_data.variables;
|
||||
let rigid_variables = vars.rigid_vars.iter().chain(vars.able_vars.iter()).copied();
|
||||
let infer_variables = vars.flex_vars.iter().copied();
|
||||
|
||||
def_pattern_state
|
||||
.constraints
|
||||
.push(constraints.equal_types_var(
|
||||
member_data.signature_var,
|
||||
Expected::NoExpectation(member_data.signature.clone()),
|
||||
signature_var,
|
||||
Expected::NoExpectation(signature.clone()),
|
||||
Category::Storage(file!(), line!()),
|
||||
Region::zero(),
|
||||
));
|
||||
|
|
|
@ -3679,22 +3679,19 @@ fn run_solve_solve(
|
|||
|
||||
// STORE ABILITIES
|
||||
let module_id = module.module_id;
|
||||
let known_specializations =
|
||||
abilities_store
|
||||
.get_known_specializations()
|
||||
.filter(|(member, typ)| {
|
||||
let solved_specializations: SolvedSpecializations = abilities_store
|
||||
.iter_specializations()
|
||||
.filter(|((member, typ), _)| {
|
||||
// This module solved this specialization if either the member or the type comes from the
|
||||
// module.
|
||||
member.module_id() == module_id || typ.module_id() == module_id
|
||||
});
|
||||
})
|
||||
.collect();
|
||||
|
||||
let mut solved_specializations: SolvedSpecializations = VecMap::default();
|
||||
let mut specialization_symbols = VecSet::default();
|
||||
for (member, typ) in known_specializations {
|
||||
let specialization = abilities_store.get_specialization(member, typ).unwrap();
|
||||
specialization_symbols.insert(specialization.symbol);
|
||||
solved_specializations.insert((member, typ), specialization);
|
||||
}
|
||||
let specialization_symbols: VecSet<_> = solved_specializations
|
||||
.values()
|
||||
.map(|ms| ms.symbol)
|
||||
.collect();
|
||||
// END STORE ABILITIES
|
||||
|
||||
// Expose anything that is explicitly exposed by the header, or is a specialization of an
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue