From d615b4f88987d0944347fbdff43e1ec23482dbb3 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Tue, 27 Aug 2024 18:52:40 +0200 Subject: [PATCH] Fix incongruous panic when annotation is missing from Datum. It's fine for the argument to not be annotated; in which case we simply default back to an `Option`. --- crates/aiken-project/src/blueprint/validator.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/aiken-project/src/blueprint/validator.rs b/crates/aiken-project/src/blueprint/validator.rs index 7146d7ee..1be58a9b 100644 --- a/crates/aiken-project/src/blueprint/validator.rs +++ b/crates/aiken-project/src/blueprint/validator.rs @@ -140,8 +140,10 @@ impl Validator { .map(|datum| { match datum.tipo.as_ref() { Type::App { module: module_name, name, args, .. } if module_name.is_empty() && name == well_known::OPTION => { - let Some(Annotation::Constructor { arguments, .. }) = datum.annotation.as_ref() else { - panic!("Datum isn't an option but should be; this should have been caught by the type-checker!"); + let annotation = if let Some(Annotation::Constructor { arguments, .. }) = datum.annotation.as_ref() { + arguments.first().cloned().expect("Datum isn't an option but should be; this should have been caught by the type-checker!") + } else { + Annotation::data(datum.location) }; Annotated::from_type( @@ -149,7 +151,7 @@ impl Validator { tipo_or_annotation(module, &TypedArg { arg_name: datum.arg_name.clone(), location: datum.location, - annotation: arguments.first().cloned(), + annotation: Some(annotation), doc: datum.doc.clone(), is_validator_param: datum.is_validator_param, tipo: args.first().expect("Option always have a single type argument.").clone()