mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Merge pull request #5179 from roc-lang/i5143-tuple-abilities
Implement ability obligation checking and derivation for tuples
This commit is contained in:
commit
61dd5cc8c7
36 changed files with 4225 additions and 2296 deletions
|
@ -33,6 +33,11 @@ test_key_eq! {
|
|||
v!({ a: v!(U8), b: v!(U8), }),
|
||||
v!({ ?a: v!(U8), ?b: v!(U8), })
|
||||
|
||||
same_tuple:
|
||||
v!((v!(U8), v!(U16),)), v!((v!(U8), v!(U16),))
|
||||
same_tuple_fields_diff_types:
|
||||
v!((v!(U8), v!(U16),)), v!((v!(U32), v!(U64),))
|
||||
|
||||
same_tag_union:
|
||||
v!([ A v!(U8) v!(STR), B v!(STR) ]), v!([ A v!(U8) v!(STR), B v!(STR) ])
|
||||
same_tag_union_tags_diff_types:
|
||||
|
@ -78,6 +83,9 @@ test_key_neq! {
|
|||
record_empty_vs_nonempty:
|
||||
v!(EMPTY_RECORD), v!({ a: v!(U8), })
|
||||
|
||||
different_tuple_arities:
|
||||
v!((v!(U8), v!(U16),)), v!((v!(U8), v!(U16), v!(U32),))
|
||||
|
||||
different_tag_union_tags:
|
||||
v!([ A v!(U8) ]), v!([ B v!(U8) ])
|
||||
tag_union_empty_vs_nonempty:
|
||||
|
@ -265,6 +273,29 @@ fn two_field_record() {
|
|||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_field_tuple() {
|
||||
derive_test(ToEncoder, v!((v!(U8), v!(STR),)), |golden| {
|
||||
assert_snapshot!(golden, @r###"
|
||||
# derived for ( U8, Str )*
|
||||
# ( val, val1 )* -[[toEncoder_(arity:2)(0)]]-> Encoder fmt | fmt has EncoderFormatting, val has Encoding, val1 has Encoding
|
||||
# ( val, val1 )a -[[toEncoder_(arity:2)(0)]]-> (List U8, fmt -[[custom(2) ( val, val1 )a]]-> List U8) | fmt has EncoderFormatting, val has Encoding, val1 has Encoding
|
||||
# Specialization lambda sets:
|
||||
# @<1>: [[toEncoder_(arity:2)(0)]]
|
||||
# @<2>: [[custom(2) ( val, val1 )*]] | val has Encoding, val1 has Encoding
|
||||
#Derived.toEncoder_(arity:2) =
|
||||
\#Derived.tup ->
|
||||
custom
|
||||
\#Derived.bytes, #Derived.fmt ->
|
||||
appendWith
|
||||
#Derived.bytes
|
||||
(tuple [toEncoder #Derived.tup.0, toEncoder #Derived.tup.1])
|
||||
#Derived.fmt
|
||||
"###
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "NOTE: this would never actually happen, because [] is uninhabited, and hence toEncoder can never be called with a value of []!
|
||||
Rightfully it induces broken assertions in other parts of the compiler, so we ignore it."]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue