fix: blueprints gen failing on List
closes #569 * added new methods to Definitions it doesn't use expect * lookup was failing for the special map/pair case when resolving list generics Co-authored-by: Pi <pi@sundaeswap.finance>
This commit is contained in:
		
							parent
							
								
									6609ab335c
								
							
						
					
					
						commit
						9c29f4f26b
					
				|  | @ -33,7 +33,7 @@ impl<T> Definitions<T> { | ||||||
|         self.inner.is_empty() |         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> { |     pub fn lookup(&self, reference: &Reference) -> Option<&T> { | ||||||
|         self.inner |         self.inner | ||||||
|             .get(&reference.as_key()) |             .get(&reference.as_key()) | ||||||
|  | @ -43,6 +43,11 @@ impl<T> Definitions<T> { | ||||||
|             ) |             ) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /// 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.
 |     /// Merge two set of definitions together. Prioritize callee.
 | ||||||
|     pub fn merge(&mut self, other: &mut Definitions<T>) { |     pub fn merge(&mut self, other: &mut Definitions<T>) { | ||||||
|         self.inner.append(&mut other.inner); |         self.inner.append(&mut other.inner); | ||||||
|  |  | ||||||
|  | @ -293,17 +293,11 @@ impl Annotated<Schema> { | ||||||
|                             // from the PlutusTx / LedgerApi Haskell codebase, which encodes some elements
 |                             // 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
 |                             // as such. We don't have a concept of language maps in Aiken, so we simply
 | ||||||
|                             // make all types abide by this convention.
 |                             // make all types abide by this convention.
 | ||||||
|                             let data = match definitions |                             let data = match definitions.try_lookup(&generic).cloned() { | ||||||
|                                 .lookup(&generic) |                                 Some(Annotated { | ||||||
|                                 .expect( |  | ||||||
|                                     "Generic type argument definition was registered just above.", |  | ||||||
|                                 ) |  | ||||||
|                                 .clone() |  | ||||||
|                             { |  | ||||||
|                                 Annotated { |  | ||||||
|                                     annotated: Schema::Data(Data::List(Items::Many(xs))), |                                     annotated: Schema::Data(Data::List(Items::Many(xs))), | ||||||
|                                     .. |                                     .. | ||||||
|                                 } if xs.len() == 2 => { |                                 }) if xs.len() == 2 => { | ||||||
|                                     definitions.remove(&generic); |                                     definitions.remove(&generic); | ||||||
|                                     Data::Map( |                                     Data::Map( | ||||||
|                                         xs.first() |                                         xs.first() | ||||||
|  | @ -314,6 +308,7 @@ impl Annotated<Schema> { | ||||||
|                                             .to_owned(), |                                             .to_owned(), | ||||||
|                                     ) |                                     ) | ||||||
|                                 } |                                 } | ||||||
|  | 
 | ||||||
|                                 _ => Data::List(Items::One(Declaration::Referenced(generic))), |                                 _ => Data::List(Items::One(Declaration::Referenced(generic))), | ||||||
|                             }; |                             }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -89,27 +89,29 @@ impl Validator { | ||||||
| 
 | 
 | ||||||
|         let mut definitions = Definitions::new(); |         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::<Result<_, _>>()?; | ||||||
|  | 
 | ||||||
|         Ok(Validator { |         Ok(Validator { | ||||||
|             title: format!("{}.{}", &module.name, &func.name), |             title: format!("{}.{}", &module.name, &func.name), | ||||||
|             description: None, |             description: func.doc.clone(), | ||||||
|             parameters: params |             parameters, | ||||||
|                 .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::<Result<_, _>>()?, |  | ||||||
|             datum: datum |             datum: datum | ||||||
|                 .map(|datum| { |                 .map(|datum| { | ||||||
|                     Annotated::from_type(modules.into(), &datum.tipo, &mut definitions).map_err( |                     Annotated::from_type(modules.into(), &datum.tipo, &mut definitions).map_err( | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 rvcas
						rvcas