1
1
mirror of https://github.com/tweag/nickel.git synced 2024-10-06 16:18:08 +03:00

Add tests for type eq of contracts

This commit is contained in:
Yann Hamdaoui 2022-08-30 17:33:52 +02:00
parent 826cada625
commit 290253cf33
2 changed files with 54 additions and 0 deletions

View File

@ -204,6 +204,43 @@ let typecheck = [
# The (| ExportFormat) cast is only temporary, and can be removed once #671
# (https://github.com/tweag/nickel/issues/671) is closed
(record.update "foo" 5 {foo = 1}) : {_: Num},
# contracts_equality
let lib = {
Contract = fun label value => value,
} in
let Proxy1 = lib.Contract in
let Proxy2 = Proxy1 in
[
{
identity : lib.Contract = (null | lib.Contract),
foo : lib.Contract = identity,
bar : Proxy1 = foo,
baz : Proxy2 = foo,
baz' : Proxy2 = bar,
# composite type
record: {arrow: Dyn -> lib.Contract, dict: {_: Array Proxy2}} = {
arrow = fun _x => (_x | Proxy2),
dict : {_ : _} = {elt = [foo]},
},
# local definition
inline = (let InlineProxy = Proxy2 in foo : InlineProxy),
},
# the following tests were initially failing while the ones above weren't,
# for reasons specific to the handling of type wildcard. We keep both version to
# make sure that type wildcards behave correctly with respect to contract
# equality.
{
identity : lib.Contract = (null | lib.Contract),
foo : lib.Contract = identity,
bar : Proxy1 = foo,
baz : Proxy2 = foo,
baz' : Proxy2 = bar,
inline = (let InlineProxy = Proxy2 in foo : InlineProxy),
},
],
] in
true

View File

@ -277,3 +277,20 @@ g"#
))
);
}
#[test]
fn locally_different_flat_types() {
assert_matches!(
type_check_expr(
"let lib = {Contract = fun label value => value} in
let foo | lib.Contract = null in
let lib = {Contract = fun label value => value} in
foo : lib.Contract"
),
Err(TypecheckError::TypeMismatch(
Types(AbsType::Flat(..)),
Types(AbsType::Flat(..)),
_
))
);
}