From 96387e3437395aee9f87383a2696dfafc66499b0 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Fri, 22 Mar 2024 16:04:09 +0100 Subject: [PATCH] Fixes #767 Co-authored-by: @rvcas --- CHANGELOG.md | 1 + crates/aiken-lang/src/tests/check.rs | 51 ++++++++++++++++++++++++++++ crates/aiken-lang/src/tipo/pipe.rs | 2 +- 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fe2bae6..b2d40e72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ - **aiken-lang**: function aliases now resolved to the module and function name in codegen. @Microproofs - **aiken-lang**: fix indentation of pipelines to remain a multiple of the base indent increment. @KtorZ - **aiken-lang**: forbid presence of non-serialisable data-types in compound structures like List and Tuple. @KtorZ +- **aiken-lang**: fix 'given' arity reported by 'incorrect arity' error message. @rvcas ### Changed diff --git a/crates/aiken-lang/src/tests/check.rs b/crates/aiken-lang/src/tests/check.rs index bac51a06..ff599dc8 100644 --- a/crates/aiken-lang/src/tests/check.rs +++ b/crates/aiken-lang/src/tests/check.rs @@ -1595,6 +1595,57 @@ fn pipe_with_wrong_type_and_full_args() { )) } +#[test] +fn pipe_wrong_arity_partially_applied() { + let source_code = r#" + fn f(_a: Int, _b: Int, _c: Int) -> Int { + todo + } + + test foo() { + 0 |> f(0) + } + "#; + + assert!(matches!( + check(parse(source_code)), + Err((_, Error::IncorrectFieldsArity { given, expected, .. })) if given == 2 && expected == 3 + )) +} + +#[test] +fn pipe_wrong_arity_fully_saturated() { + let source_code = r#" + fn f(_a: Int, _b: Int, _c: Int) -> Int { + todo + } + + test foo() { + 0 |> f(0, 0, 0) + } + "#; + + assert!(matches!( + check(parse(source_code)), + Err((_, Error::NotFn { .. })) + )) +} + +#[test] +fn pipe_wrong_arity_fully_saturated_return_fn() { + let source_code = r#" + fn f(_a: Int, _b: Int, _c: Int) -> fn(Int) -> Int { + todo + } + + test foo() { + (0 |> f(0, 0, 0)) == 0 + } + "#; + + assert!(check(parse(source_code)).is_ok()); +} + #[test] fn fuzzer_ok_basic() { let source_code = r#" diff --git a/crates/aiken-lang/src/tipo/pipe.rs b/crates/aiken-lang/src/tipo/pipe.rs index 613ce5ab..dc2e21b1 100644 --- a/crates/aiken-lang/src/tipo/pipe.rs +++ b/crates/aiken-lang/src/tipo/pipe.rs @@ -92,7 +92,7 @@ impl<'a, 'b, 'c> PipeTyper<'a, 'b, 'c> { match fun.tipo().fn_arity() { // Rewrite as right(left, ..args) - Some(arity) if arity == arguments.len() + 1 => { + Some(arity) if arguments.len() < arity => { self.infer_insert_pipe(fun, arguments, location)? }