Don't re-report obligations that we know were seen elsewhere

This commit is contained in:
Ayaz Hafiz 2022-07-25 13:27:42 -04:00
parent 6b9c1cb690
commit bb14b649a2
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58
2 changed files with 17 additions and 6 deletions

View File

@ -238,8 +238,10 @@ impl DeferredObligations {
// Go through and attach generic "type does not implement ability" errors, if they were not
// part of a larger context.
for mia in incomplete_not_in_context.into_iter() {
if let Err(unfulfilled) = obligation_cache.check_one(subs, mia) {
if !reported_in_context.contains(&mia) {
// If the obligation is already cached, we must have already reported it in another
// context.
if !obligation_cache.has_cached(mia) && !reported_in_context.contains(&mia) {
if let Err(unfulfilled) = obligation_cache.check_one(subs, mia) {
problems.push(TypeError::UnfulfilledAbility(unfulfilled.clone()));
}
}
@ -274,6 +276,19 @@ impl ObligationCache<'_> {
}
}
fn has_cached(&self, mia: MustImplementAbility) -> bool {
match mia.typ {
Obligated::Opaque(opaque) => self.impl_cache.contains_key(&ImplKey {
opaque,
ability: mia.ability,
}),
Obligated::Adhoc(_) => {
// ad-hoc obligations are never cached
false
}
}
}
fn check_adhoc(&mut self, subs: &mut Subs, var: Variable, ability: Symbol) -> ObligationResult {
// Not worth caching ad-hoc checks because variables are unlikely to be the same between
// independent queries.

View File

@ -9109,10 +9109,6 @@ All branches in an `if` must have the same type!
Tip: `A` does not implement `Encoding`. Consider adding a custom
implementation or `has Encode.Encoding` to the definition of `A`.
INCOMPLETE ABILITY IMPLEMENTATION /code/proj/Main.roc
The type `A` does not fully implement the ability `Encoding`.
"###
);