From 961806617f73536f6b68a702a15ff948878ed6a5 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Wed, 13 Mar 2024 13:05:44 +0100 Subject: [PATCH] Add more failing tests for expecting on into opaque types. --- crates/aiken-lang/src/tests/check.rs | 82 ++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/crates/aiken-lang/src/tests/check.rs b/crates/aiken-lang/src/tests/check.rs index 0bc67def..f794d7b2 100644 --- a/crates/aiken-lang/src/tests/check.rs +++ b/crates/aiken-lang/src/tests/check.rs @@ -1812,16 +1812,15 @@ fn forbid_expect_into_opaque_type_from_data() { } #[test] -fn forbid_expect_into_opaque_type_constructor() { +fn forbid_expect_into_opaque_type_constructor_without_typecasting() { let source_code = r#" opaque type Thing { Foo(Int) Bar(Int) } - fn bar(n: Thing) { - expect Foo(a) = n - + fn bar(thing: Thing) { + expect Foo(a) = thing a } "#; @@ -1831,3 +1830,78 @@ fn forbid_expect_into_opaque_type_constructor() { Err((_, Error::ExpectOnOpaqueType { .. })) )) } + +#[test] +fn forbid_expect_into_opaque_type_constructor_with_typecasting() { + let source_code = r#" + opaque type Thing { + Foo(Int) + Bar(Int) + } + + fn bar(data: Data) { + expect Foo(a): Thing = data + a + } + "#; + + assert!(matches!( + check(parse(source_code)), + Err((_, Error::ExpectOnOpaqueType { .. })) + )) +} + +#[test] +fn forbid_expect_into_nested_opaque_in_record_without_typecasting() { + let source_code = r#" + opaque type Thing { inner: Int } + + type Foo { foo: Thing } + + fn bar(thing: Thing) { + expect Foo { foo: Thing { inner } } : Foo = thing + Void + } + "#; + + assert!(matches!( + check(parse(source_code)), + Err((_, Error::ExpectOnOpaqueType { .. })) + )) +} + +#[test] +fn forbid_expect_into_nested_opaque_in_record_with_typecasting() { + let source_code = r#" + opaque type Thing { inner: Int } + + type Foo { foo: Thing } + + fn bar(a: Data) { + expect Foo { foo: Thing { inner } } : Foo = a + Void + } + "#; + + assert!(matches!( + check(parse(source_code)), + Err((_, Error::ExpectOnOpaqueType { .. })) + )) +} + +#[test] +fn forbid_expect_into_nested_opaque_in_list() { + let source_code = r#" + opaque type Thing { inner: Int } + + fn bar(a: Data) { + expect [x]: List = [a] + Void + } + "#; + + assert!(matches!( + check(parse(source_code)), + Err((_, Error::ExpectOnOpaqueType { .. })) + )) +}