Add Inspect to obligation checker

This commit is contained in:
Richard Feldman 2023-08-28 21:46:08 -04:00 committed by Brendan Hansknecht
parent 5a872a1bdd
commit fb9e0fc777
No known key found for this signature in database
GPG Key ID: 0EA784685083E75B

View File

@ -373,7 +373,11 @@ impl ObligationCache {
let ImplKey { opaque, ability } = impl_key; let ImplKey { opaque, ability } = impl_key;
let has_declared_impl = abilities_store.has_declared_implementation(opaque, ability); // Every type has the Inspect ability automatically, even opaques with no `implements` declaration.
// (Those opaques get a default implementation that returns something along the lines of "<opaque>")
let is_inspect = ability == Symbol::INSPECT_INSPECT_ABILITY;
let has_known_impl =
is_inspect || abilities_store.has_declared_implementation(opaque, ability);
// Some builtins, like Float32 and Bool, would have a cyclic dependency on Encode/Decode/etc. // Some builtins, like Float32 and Bool, would have a cyclic dependency on Encode/Decode/etc.
// if their Roc implementations explicitly defined some abilities they support. // if their Roc implementations explicitly defined some abilities they support.
@ -385,15 +389,13 @@ impl ObligationCache {
_ => false, _ => false,
}; };
let has_declared_impl = has_declared_impl || builtin_opaque_impl_ok(); let obligation_result = if has_known_impl || builtin_opaque_impl_ok() {
Ok(())
let obligation_result = if !has_declared_impl { } else {
Err(Unfulfilled::OpaqueDoesNotImplement { Err(Unfulfilled::OpaqueDoesNotImplement {
typ: opaque, typ: opaque,
ability, ability,
}) })
} else {
Ok(())
}; };
self.impl_cache.insert(impl_key, obligation_result); self.impl_cache.insert(impl_key, obligation_result);