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<Data>`.
This commit is contained in:
KtorZ 2024-08-27 18:52:40 +02:00
parent 4003343444
commit d615b4f889
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
1 changed files with 5 additions and 3 deletions

View File

@ -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()