diff --git a/crates/aiken-project/src/blueprint/definitions.rs b/crates/aiken-project/src/blueprint/definitions.rs index 5becf7cb..bdd1e01e 100644 --- a/crates/aiken-project/src/blueprint/definitions.rs +++ b/crates/aiken-project/src/blueprint/definitions.rs @@ -33,7 +33,7 @@ impl Definitions { self.inner.is_empty() } - /// Retrieve a definition, if it exists. + /// Retrieve a definition, if it exists; fail if not resolved pub fn lookup(&self, reference: &Reference) -> Option<&T> { self.inner .get(&reference.as_key()) @@ -43,6 +43,11 @@ impl Definitions { ) } + /// Retrieve a definition, if it exists and is resolved. + pub fn try_lookup(&self, reference: &Reference) -> Option<&T> { + self.inner.get(&reference.as_key()).and_then(|v| v.as_ref()) + } + /// Merge two set of definitions together. Prioritize callee. pub fn merge(&mut self, other: &mut Definitions) { self.inner.append(&mut other.inner); diff --git a/crates/aiken-project/src/blueprint/schema.rs b/crates/aiken-project/src/blueprint/schema.rs index 41f5f2d0..4bbfedbb 100644 --- a/crates/aiken-project/src/blueprint/schema.rs +++ b/crates/aiken-project/src/blueprint/schema.rs @@ -293,17 +293,11 @@ impl Annotated { // from the PlutusTx / LedgerApi Haskell codebase, which encodes some elements // as such. We don't have a concept of language maps in Aiken, so we simply // make all types abide by this convention. - let data = match definitions - .lookup(&generic) - .expect( - "Generic type argument definition was registered just above.", - ) - .clone() - { - Annotated { + let data = match definitions.try_lookup(&generic).cloned() { + Some(Annotated { annotated: Schema::Data(Data::List(Items::Many(xs))), .. - } if xs.len() == 2 => { + }) if xs.len() == 2 => { definitions.remove(&generic); Data::Map( xs.first() @@ -314,6 +308,7 @@ impl Annotated { .to_owned(), ) } + _ => Data::List(Items::One(Declaration::Referenced(generic))), }; diff --git a/crates/aiken-project/src/blueprint/validator.rs b/crates/aiken-project/src/blueprint/validator.rs index 46aea288..ff252619 100644 --- a/crates/aiken-project/src/blueprint/validator.rs +++ b/crates/aiken-project/src/blueprint/validator.rs @@ -89,27 +89,29 @@ impl Validator { let mut definitions = Definitions::new(); + let parameters = params + .iter() + .map(|param| { + Annotated::from_type(modules.into(), ¶m.tipo, &mut definitions) + .map(|schema| Parameter { + title: Some(param.arg_name.get_label()), + schema, + }) + .map_err(|error| Error::Schema { + error, + location: param.location, + source_code: NamedSource::new( + module.input_path.display().to_string(), + module.code.clone(), + ), + }) + }) + .collect::>()?; + Ok(Validator { title: format!("{}.{}", &module.name, &func.name), - description: None, - parameters: params - .iter() - .map(|param| { - Annotated::from_type(modules.into(), ¶m.tipo, &mut definitions) - .map(|schema| Parameter { - title: Some(param.arg_name.get_label()), - schema, - }) - .map_err(|error| Error::Schema { - error, - location: param.location, - source_code: NamedSource::new( - module.input_path.display().to_string(), - module.code.clone(), - ), - }) - }) - .collect::>()?, + description: func.doc.clone(), + parameters, datum: datum .map(|datum| { Annotated::from_type(modules.into(), &datum.tipo, &mut definitions).map_err(