mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 06:55:15 +00:00
Check for builtin opaque types that always have a derived impl
This commit is contained in:
parent
5d1198ae1f
commit
19e93962cb
1 changed files with 25 additions and 0 deletions
|
@ -437,6 +437,11 @@ struct Descend(bool);
|
|||
trait DerivableVisitor {
|
||||
const ABILITY: Symbol;
|
||||
|
||||
#[inline(always)]
|
||||
fn is_derivable_builtin_opaque(_symbol: Symbol) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn visit_flex(var: Variable) -> Result<(), DerivableError> {
|
||||
Err(DerivableError::NotDerivable(var))
|
||||
|
@ -612,10 +617,20 @@ trait DerivableVisitor {
|
|||
|
||||
Erroneous(_) => return Err(NotDerivable(var)),
|
||||
},
|
||||
Alias(
|
||||
Symbol::NUM_NUM | Symbol::NUM_INTEGER | Symbol::NUM_FLOATINGPOINT,
|
||||
_alias_variables,
|
||||
real_var,
|
||||
AliasKind::Opaque,
|
||||
) => {
|
||||
// Numbers: always decay until a ground is hit.
|
||||
stack.push(real_var);
|
||||
}
|
||||
Alias(opaque, _alias_variables, _real_var, AliasKind::Opaque) => {
|
||||
if obligation_cache
|
||||
.check_opaque_and_read(abilities_store, opaque, Self::ABILITY)
|
||||
.is_err()
|
||||
&& !Self::is_derivable_builtin_opaque(opaque)
|
||||
{
|
||||
return Err(NotDerivable(var));
|
||||
}
|
||||
|
@ -643,6 +658,11 @@ struct DeriveEncoding;
|
|||
impl DerivableVisitor for DeriveEncoding {
|
||||
const ABILITY: Symbol = Symbol::ENCODE_ENCODING;
|
||||
|
||||
#[inline(always)]
|
||||
fn is_derivable_builtin_opaque(symbol: Symbol) -> bool {
|
||||
is_builtin_number_alias(symbol)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn visit_recursion(_var: Variable) -> Result<Descend, DerivableError> {
|
||||
Ok(Descend(true))
|
||||
|
@ -703,6 +723,11 @@ struct DeriveDecoding;
|
|||
impl DerivableVisitor for DeriveDecoding {
|
||||
const ABILITY: Symbol = Symbol::DECODE_DECODING;
|
||||
|
||||
#[inline(always)]
|
||||
fn is_derivable_builtin_opaque(symbol: Symbol) -> bool {
|
||||
is_builtin_number_alias(symbol)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn visit_recursion(_var: Variable) -> Result<Descend, DerivableError> {
|
||||
Ok(Descend(true))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue