mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 20:28:02 +00:00
Add derive key tests for able ext vars
This commit is contained in:
parent
a8bd529664
commit
a01583efff
4 changed files with 58 additions and 22 deletions
|
@ -75,6 +75,15 @@ fn derivable_record_ext_flex_var() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derivable_record_ext_flex_able_var() {
|
||||
check_derivable(
|
||||
Decoder,
|
||||
v!({ a: v!(STR), }a has Symbol::DECODE_DECODER ),
|
||||
DeriveKey::Decoder(FlatDecodableKey::Record(vec!["a".into()])),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derivable_record_with_record_ext() {
|
||||
check_derivable(
|
||||
|
|
|
@ -127,6 +127,15 @@ fn derivable_record_ext_flex_var() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derivable_record_ext_flex_able_var() {
|
||||
check_derivable(
|
||||
ToEncoder,
|
||||
v!({ a: v!(STR), }a has Symbol::ENCODE_TO_ENCODER),
|
||||
DeriveKey::ToEncoder(FlatEncodableKey::Record(vec!["a".into()])),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derivable_record_with_record_ext() {
|
||||
check_derivable(
|
||||
|
@ -145,6 +154,15 @@ fn derivable_tag_ext_flex_var() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derivable_tag_ext_flex_able_var() {
|
||||
check_derivable(
|
||||
ToEncoder,
|
||||
v!([ A v!(STR) ]a has Symbol::ENCODE_TO_ENCODER),
|
||||
DeriveKey::ToEncoder(FlatEncodableKey::TagUnion(vec![("A".into(), 1)])),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn derivable_tag_with_tag_ext() {
|
||||
check_derivable(
|
||||
|
|
|
@ -56,7 +56,7 @@ fn module_source_and_path(builtin: DeriveBuiltin) -> (ModuleId, &'static str, Pa
|
|||
/// DSL for creating [`Content`][roc_types::subs::Content].
|
||||
#[macro_export]
|
||||
macro_rules! v {
|
||||
({ $($field:ident: $make_v:expr,)* $(?$opt_field:ident : $make_opt_v:expr,)* }$( $ext:tt )?) => {{
|
||||
({ $($field:ident: $make_v:expr,)* $(?$opt_field:ident : $make_opt_v:expr,)* }$( $($ext:tt)+ )?) => {{
|
||||
#[allow(unused)]
|
||||
use roc_types::types::RecordField;
|
||||
use roc_types::subs::{Subs, RecordFields, Content, FlatType, Variable};
|
||||
|
@ -71,29 +71,11 @@ macro_rules! v {
|
|||
|
||||
#[allow(unused_mut, unused)]
|
||||
let mut ext = Variable::EMPTY_RECORD;
|
||||
$( ext = $crate::v!($ext)(subs); )?
|
||||
$( ext = $crate::v!($($ext)+)(subs); )?
|
||||
|
||||
roc_derive::synth_var(subs, Content::Structure(FlatType::Record(fields, ext)))
|
||||
}
|
||||
}};
|
||||
([ $($tag:ident $($payload:expr)*),* ]$( $ext:tt )?) => {{
|
||||
#[allow(unused)]
|
||||
use roc_types::subs::{Subs, UnionTags, Content, FlatType, Variable};
|
||||
#[allow(unused)]
|
||||
use roc_module::ident::TagName;
|
||||
|subs: &mut Subs| {
|
||||
$(
|
||||
let $tag = vec![ $( $payload(subs), )* ];
|
||||
)*
|
||||
let tags = UnionTags::insert_into_subs::<_, Vec<Variable>>(subs, vec![ $( (TagName(stringify!($tag).into()), $tag) ,)* ]);
|
||||
|
||||
#[allow(unused_mut, unused)]
|
||||
let mut ext = Variable::EMPTY_TAG_UNION;
|
||||
$( ext = $crate::v!($ext)(subs); )?
|
||||
|
||||
roc_derive::synth_var(subs, Content::Structure(FlatType::TagUnion(tags, ext)))
|
||||
}
|
||||
}};
|
||||
([ $($tag:ident $($payload:expr)*),* ] as $rec_var:ident) => {{
|
||||
use roc_types::subs::{Subs, SubsIndex, Variable, Content, FlatType, UnionTags};
|
||||
use roc_module::ident::TagName;
|
||||
|
@ -118,6 +100,24 @@ macro_rules! v {
|
|||
tag_union_var
|
||||
}
|
||||
}};
|
||||
([ $($tag:ident $($payload:expr)*),* ]$( $($ext:tt)+ )?) => {{
|
||||
#[allow(unused)]
|
||||
use roc_types::subs::{Subs, UnionTags, Content, FlatType, Variable};
|
||||
#[allow(unused)]
|
||||
use roc_module::ident::TagName;
|
||||
|subs: &mut Subs| {
|
||||
$(
|
||||
let $tag = vec![ $( $payload(subs), )* ];
|
||||
)*
|
||||
let tags = UnionTags::insert_into_subs::<_, Vec<Variable>>(subs, vec![ $( (TagName(stringify!($tag).into()), $tag) ,)* ]);
|
||||
|
||||
#[allow(unused_mut, unused)]
|
||||
let mut ext = Variable::EMPTY_TAG_UNION;
|
||||
$( ext = $crate::v!($($ext)+)(subs); )?
|
||||
|
||||
roc_derive::synth_var(subs, Content::Structure(FlatType::TagUnion(tags, ext)))
|
||||
}
|
||||
}};
|
||||
(Symbol::$sym:ident $($arg:expr)*) => {{
|
||||
use roc_types::subs::{Subs, SubsSlice, Content, FlatType};
|
||||
use roc_module::symbol::Symbol;
|
||||
|
@ -153,6 +153,15 @@ macro_rules! v {
|
|||
use roc_types::subs::{Subs, Content};
|
||||
|subs: &mut Subs| { roc_derive::synth_var(subs, Content::FlexVar(None)) }
|
||||
}};
|
||||
($name:ident has $ability:path) => {{
|
||||
use roc_types::subs::{Subs, SubsIndex, Content};
|
||||
|subs: &mut Subs| {
|
||||
let name_index =
|
||||
SubsIndex::push_new(&mut subs.field_names, stringify!($name).into());
|
||||
|
||||
roc_derive::synth_var(subs, Content::FlexAbleVar(Some(name_index), $ability))
|
||||
}
|
||||
}};
|
||||
(^$rec_var:ident) => {{
|
||||
use roc_types::subs::{Subs};
|
||||
|_: &mut Subs| { $rec_var }
|
||||
|
|
|
@ -2689,10 +2689,10 @@ pub fn gather_fields_unsorted_iter(
|
|||
}
|
||||
|
||||
Structure(EmptyRecord) => break,
|
||||
FlexVar(_) => break,
|
||||
FlexVar(_) | FlexAbleVar(..) => break,
|
||||
|
||||
// TODO investigate apparently this one pops up in the reporting tests!
|
||||
RigidVar(_) => break,
|
||||
RigidVar(_) | RigidAbleVar(..) => break,
|
||||
|
||||
// Stop on errors in the record
|
||||
Error => break,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue