mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 20:28:02 +00:00
Derive key for Decoding tuples
This commit is contained in:
parent
92aff265ae
commit
5e0a6e5926
3 changed files with 20 additions and 3 deletions
|
@ -2,7 +2,7 @@ use roc_module::{ident::Lowercase, symbol::Symbol};
|
|||
use roc_types::subs::{Content, FlatType, Subs, Variable};
|
||||
|
||||
use crate::{
|
||||
util::{check_derivable_ext_var, debug_name_record},
|
||||
util::{check_derivable_ext_var, debug_name_record, debug_name_tuple},
|
||||
DeriveError,
|
||||
};
|
||||
|
||||
|
@ -18,6 +18,7 @@ pub enum FlatDecodableKey {
|
|||
|
||||
// Unfortunate that we must allocate here, c'est la vie
|
||||
Record(Vec<Lowercase>),
|
||||
Tuple(u32),
|
||||
}
|
||||
|
||||
impl FlatDecodableKey {
|
||||
|
@ -25,6 +26,7 @@ impl FlatDecodableKey {
|
|||
match self {
|
||||
FlatDecodableKey::List() => "list".to_string(),
|
||||
FlatDecodableKey::Record(fields) => debug_name_record(fields),
|
||||
FlatDecodableKey::Tuple(arity) => debug_name_tuple(*arity),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,8 +63,14 @@ impl FlatDecodable {
|
|||
|
||||
Ok(Key(FlatDecodableKey::Record(field_names)))
|
||||
}
|
||||
FlatType::Tuple(_elems, _ext) => {
|
||||
todo!()
|
||||
FlatType::Tuple(elems, ext) => {
|
||||
let (elems_iter, ext) = elems.sorted_iterator_and_ext(subs, ext);
|
||||
|
||||
check_derivable_ext_var(subs, ext, |ext| {
|
||||
matches!(ext, Content::Structure(FlatType::EmptyTuple))
|
||||
})?;
|
||||
|
||||
Ok(Key(FlatDecodableKey::Tuple(elems_iter.count() as _)))
|
||||
}
|
||||
FlatType::TagUnion(_tags, _ext) | FlatType::RecursiveTagUnion(_, _tags, _ext) => {
|
||||
Err(Underivable) // yet
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue