From 25ebdc25275964f1fdd9dae9aa3b8de81e295236 Mon Sep 17 00:00:00 2001 From: rvcas Date: Wed, 6 Mar 2024 14:15:00 -0500 Subject: [PATCH] fix: validator args unexpectedly unbound closes #852 --- crates/aiken-lang/src/ast.rs | 9 +++++ crates/aiken-lang/src/tipo/environment.rs | 12 ++++++ examples/acceptance_tests/096/aiken.lock | 15 ++++++++ examples/acceptance_tests/096/aiken.toml | 14 +++++++ examples/acceptance_tests/096/plutus.json | 38 +++++++++++++++++++ .../acceptance_tests/096/validators/foo.ak | 7 ++++ 6 files changed, 95 insertions(+) create mode 100644 examples/acceptance_tests/096/aiken.lock create mode 100644 examples/acceptance_tests/096/aiken.toml create mode 100644 examples/acceptance_tests/096/plutus.json create mode 100644 examples/acceptance_tests/096/validators/foo.ak diff --git a/crates/aiken-lang/src/ast.rs b/crates/aiken-lang/src/ast.rs index 49a6848c..b3b95ab8 100644 --- a/crates/aiken-lang/src/ast.rs +++ b/crates/aiken-lang/src/ast.rs @@ -968,6 +968,15 @@ impl Annotation { } } + pub fn data(location: Span) -> Self { + Annotation::Constructor { + name: "Data".to_string(), + module: None, + arguments: vec![], + location, + } + } + pub fn is_logically_equal(&self, other: &Annotation) -> bool { match self { Annotation::Constructor { diff --git a/crates/aiken-lang/src/tipo/environment.rs b/crates/aiken-lang/src/tipo/environment.rs index 8bb9b383..6965bc95 100644 --- a/crates/aiken-lang/src/tipo/environment.rs +++ b/crates/aiken-lang/src/tipo/environment.rs @@ -1144,10 +1144,21 @@ impl<'a> Environment<'a> { params, .. }) if kind.is_validator() => { + let default_annotation = |mut arg: UntypedArg| { + if arg.annotation.is_none() { + arg.annotation = Some(Annotation::data(arg.location)); + + arg + } else { + arg + } + }; + let temp_params: Vec = params .iter() .cloned() .chain(fun.arguments.clone()) + .map(default_annotation) .collect(); self.register_function( @@ -1165,6 +1176,7 @@ impl<'a> Environment<'a> { .iter() .cloned() .chain(other.arguments.clone()) + .map(default_annotation) .collect(); self.register_function( diff --git a/examples/acceptance_tests/096/aiken.lock b/examples/acceptance_tests/096/aiken.lock new file mode 100644 index 00000000..0a72eb3c --- /dev/null +++ b/examples/acceptance_tests/096/aiken.lock @@ -0,0 +1,15 @@ +# This file was generated by Aiken +# You typically do not need to edit this file + +[[requirements]] +name = "aiken-lang/stdlib" +version = "1.7.0" +source = "github" + +[[packages]] +name = "aiken-lang/stdlib" +version = "1.7.0" +requirements = [] +source = "github" + +[etags] diff --git a/examples/acceptance_tests/096/aiken.toml b/examples/acceptance_tests/096/aiken.toml new file mode 100644 index 00000000..97bd72b9 --- /dev/null +++ b/examples/acceptance_tests/096/aiken.toml @@ -0,0 +1,14 @@ +name = "aiken-lang/acceptance_test_096" +version = "0.0.0" +license = "Apache-2.0" +description = "Aiken contracts for project 'aiken-lang/096'" + +[repository] +user = "aiken-lang" +project = "096" +platform = "github" + +[[dependencies]] +name = "aiken-lang/stdlib" +version = "1.7.0" +source = "github" diff --git a/examples/acceptance_tests/096/plutus.json b/examples/acceptance_tests/096/plutus.json new file mode 100644 index 00000000..7e064c1e --- /dev/null +++ b/examples/acceptance_tests/096/plutus.json @@ -0,0 +1,38 @@ +{ + "preamble": { + "title": "aiken-lang/acceptance_test_096", + "description": "Aiken contracts for project 'aiken-lang/096'", + "version": "0.0.0", + "plutusVersion": "v2", + "compiler": { + "name": "Aiken", + "version": "v1.0.24-alpha+ad48409" + }, + "license": "Apache-2.0" + }, + "validators": [ + { + "title": "foo.is_fourty_two", + "datum": { + "title": "dat", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "redeemer": { + "title": "rdm", + "schema": { + "$ref": "#/definitions/Data" + } + }, + "compiledCode": "583c01000032222533300453330043375e004006266e3d22010b68656c6c6f20776f726c640048810b68656c6c6f20776f726c640014a029309b2b2b9a01", + "hash": "d1a4ef5efcf38bdca9dc8eec2684d3c2004390fa6fd1b5bed6faa488" + } + ], + "definitions": { + "Data": { + "title": "Data", + "description": "Any Plutus data." + } + } +} \ No newline at end of file diff --git a/examples/acceptance_tests/096/validators/foo.ak b/examples/acceptance_tests/096/validators/foo.ak new file mode 100644 index 00000000..8813dc9f --- /dev/null +++ b/examples/acceptance_tests/096/validators/foo.ak @@ -0,0 +1,7 @@ +use aiken/transaction.{ScriptContext} + +validator { + fn is_fourty_two(dat, rdm, _ctx: ScriptContext) -> Bool { + rdm == dat && #"68656c6c6f20776f726c64" == #"68656c6c6f20776f726c64" + } +}