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 { .. })) + )) +}