diff --git a/crates/aiken-lang/src/tests/check.rs b/crates/aiken-lang/src/tests/check.rs index c8e67fda..1e4afa1b 100644 --- a/crates/aiken-lang/src/tests/check.rs +++ b/crates/aiken-lang/src/tests/check.rs @@ -2267,6 +2267,42 @@ fn allow_expect_into_opaque_type_constructor_without_typecasting_in_module() { assert!(check(parse(source_code)).is_ok()); } +#[test] +fn use_imported_type_as_namespace_for_patterns() { + let dependency = r#" + pub type Credential { + VerificationKey(ByteArray) + Script(ByteArray) + } + "#; + + let source_code = r#" + use cardano/address.{Credential, Script, VerificationKey} + + pub fn compare(left: Credential, right: Credential) -> Ordering { + when left is { + Script(left) -> + when right is { + Script(right) -> Equal + _ -> Less + } + VerificationKey(left) -> + when right is { + Script(_) -> Greater + VerificationKey(right) -> Equal + } + } + } + "#; + + let result = check_with_deps( + dbg!(parse(source_code)), + vec![(parse_as(dependency, "cardano/address"))], + ); + + assert!(matches!(result, Ok(..)), "{result:#?}"); +} + #[test] fn use_type_as_namespace_for_patterns() { let dependency = r#"