The first ability... compiles

This commit is contained in:
Ayaz Hafiz 2022-04-14 16:50:41 -04:00
parent 6b4294307f
commit b79b351136
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
7 changed files with 104 additions and 12 deletions

View file

@ -1,4 +1,5 @@
use roc_can::abilities::AbilitiesStore;
use roc_module::symbol::Symbol;
use roc_region::all::{Loc, Region};
use roc_types::subs::Subs;
use roc_types::subs::Variable;
@ -154,3 +155,23 @@ impl DeferredMustImplementAbility {
problems
}
}
/// Determines what type implements an ability member of a specialized signature, given the
/// [MustImplementAbility] constraints of the signature.
pub fn type_implementing_member(
specialization_must_implement_constraints: &[MustImplementAbility],
ability: Symbol,
) -> Symbol {
let mut ability_implementations_for_specialization = specialization_must_implement_constraints
.iter()
.filter(|mia| mia.ability == ability)
.collect::<Vec<_>>();
ability_implementations_for_specialization.dedup();
debug_assert!(ability_implementations_for_specialization.len() == 1, "Multiple variables bound to an ability - this is ambiguous and should have been caught in canonicalization");
ability_implementations_for_specialization
.pop()
.unwrap()
.typ
}