Support deriving decoder for record with arbitrary ext var

This commit is contained in:
Ayaz Hafiz 2022-08-17 09:51:44 -05:00
parent b5e59d22e3
commit 2f24c81dab
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 34 additions and 12 deletions

View file

@ -1,7 +1,10 @@
use roc_module::{ident::Lowercase, symbol::Symbol};
use roc_types::subs::{Content, FlatType, Subs, Variable};
use crate::{util::debug_name_record, DeriveError};
use crate::{
util::{check_derivable_ext_var, debug_name_record},
DeriveError,
};
#[derive(Hash)]
pub enum FlatDecodable {
@ -38,10 +41,11 @@ impl FlatDecodable {
_ => Err(Underivable),
},
FlatType::Record(fields, ext) => {
let fields_iter = match fields.unsorted_iterator(subs, ext) {
Ok(it) => it,
Err(_) => return Err(Underivable),
};
let (fields_iter, ext) = fields.unsorted_iterator_and_ext(subs, ext);
check_derivable_ext_var(subs, ext, |ext| {
matches!(ext, Content::Structure(FlatType::EmptyRecord))
})?;
let mut field_names = Vec::with_capacity(fields.len());
for (field_name, record_field) in fields_iter {