feat: annotated data for option datum

This commit is contained in:
rvcas 2024-08-23 17:15:54 -04:00 committed by KtorZ
parent d8723c5497
commit ff1464b462
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 15 additions and 11 deletions

View File

@ -22,6 +22,8 @@ mod pattern;
mod pipe; mod pipe;
pub mod pretty; pub mod pretty;
pub use environment::collapse_links;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct TypeAliasAnnotation { pub struct TypeAliasAnnotation {
pub alias: String, pub alias: String,
@ -1099,13 +1101,11 @@ impl TypeVar {
Self::Link { tipo } => tipo.get_inner_types(), Self::Link { tipo } => tipo.get_inner_types(),
Self::Unbound { .. } => vec![], Self::Unbound { .. } => vec![],
var => { var => {
vec![ vec![Type::Var {
Type::Var {
tipo: RefCell::new(var.clone()).into(), tipo: RefCell::new(var.clone()).into(),
alias: None, alias: None,
} }
.into(), .into()]
]
} }
} }
} }

View File

@ -1967,7 +1967,7 @@ pub(super) fn assert_no_labeled_arguments<A>(args: &[CallArg<A>]) -> Option<(Spa
None None
} }
pub(super) fn collapse_links(t: Rc<Type>) -> Rc<Type> { pub fn collapse_links(t: Rc<Type>) -> Rc<Type> {
if let Type::Var { tipo, alias } = t.deref() { if let Type::Var { tipo, alias } = t.deref() {
if let TypeVar::Link { tipo } = tipo.borrow().deref() { if let TypeVar::Link { tipo } = tipo.borrow().deref() {
return Type::with_alias(tipo.clone(), alias.clone()); return Type::with_alias(tipo.clone(), alias.clone());

View File

@ -10,7 +10,7 @@ use aiken_lang::{
ast::{well_known, Annotation, TypedArg, TypedFunction, TypedValidator}, ast::{well_known, Annotation, TypedArg, TypedFunction, TypedValidator},
gen_uplc::CodeGenerator, gen_uplc::CodeGenerator,
plutus_version::PlutusVersion, plutus_version::PlutusVersion,
tipo::Type, tipo::{collapse_links, Type},
}; };
use miette::NamedSource; use miette::NamedSource;
use serde; use serde;
@ -126,12 +126,16 @@ impl Validator {
.map(|datum| { .map(|datum| {
match datum.tipo.as_ref() { match datum.tipo.as_ref() {
Type::App { module: module_name, name, args, .. } if module_name.is_empty() && name == well_known::OPTION => { 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!");
};
Annotated::from_type( Annotated::from_type(
modules.into(), modules.into(),
tipo_or_annotation(module, &TypedArg { tipo_or_annotation(module, &TypedArg {
arg_name: datum.arg_name.clone(), arg_name: datum.arg_name.clone(),
location: datum.location, location: datum.location,
annotation: datum.annotation.clone(), annotation: arguments.first().cloned(),
doc: datum.doc.clone(), doc: datum.doc.clone(),
is_validator_param: datum.is_validator_param, is_validator_param: datum.is_validator_param,
tipo: args.first().expect("Option always have a single type argument.").clone() tipo: args.first().expect("Option always have a single type argument.").clone()
@ -204,7 +208,7 @@ impl Validator {
} }
pub fn tipo_or_annotation<'a>(module: &'a CheckedModule, arg: &'a TypedArg) -> &'a Type { pub fn tipo_or_annotation<'a>(module: &'a CheckedModule, arg: &'a TypedArg) -> &'a Type {
match *arg.tipo.borrow() { match collapse_links(arg.tipo.clone()).borrow() {
Type::App { Type::App {
module: ref module_name, module: ref module_name,
name: ref type_name, name: ref type_name,