fix: make sure that fallback gets it's own scope with params

This commit is contained in:
rvcas 2024-07-30 17:27:14 -04:00 committed by KtorZ
parent 1d9034573b
commit 9e866a5ec1
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
1 changed files with 37 additions and 31 deletions

View File

@ -220,44 +220,50 @@ fn infer_definition(
typed_handlers.push(typed_fun); typed_handlers.push(typed_fun);
} }
let params = params.into_iter().chain(fallback.arguments); let (typed_params, typed_fallback) = environment.in_new_scope(|environment| {
fallback.arguments = params.collect(); let temp_params = params.iter().cloned().chain(fallback.arguments);
fallback.arguments = temp_params.collect();
let mut typed_fallback = put_params_in_scope(&fallback.name, environment, &params);
infer_function(&fallback, module_name, hydrators, environment, tracing)?;
if !typed_fallback.return_type.is_bool() { let mut typed_fallback =
return Err(Error::ValidatorMustReturnBool { infer_function(&fallback, module_name, hydrators, environment, tracing)?;
return_type: typed_fallback.return_type.clone(),
location: typed_fallback.location,
});
}
let typed_params = typed_fallback if !typed_fallback.return_type.is_bool() {
.arguments return Err(Error::ValidatorMustReturnBool {
.drain(0..params_length) return_type: typed_fallback.return_type.clone(),
.map(|mut arg| { location: typed_fallback.location,
});
}
let typed_params = typed_fallback
.arguments
.drain(0..params_length)
.map(|mut arg| {
if arg.tipo.is_unbound() {
arg.tipo = builtins::data();
}
arg
})
.collect();
if typed_fallback.arguments.len() != 1 {
return Err(Error::IncorrectValidatorArity {
count: typed_fallback.arguments.len() as u32,
expected: 1,
location: typed_fallback.location,
});
}
for arg in typed_fallback.arguments.iter_mut() {
if arg.tipo.is_unbound() { if arg.tipo.is_unbound() {
arg.tipo = builtins::data(); arg.tipo = builtins::data();
} }
arg
})
.collect();
if typed_fallback.arguments.len() != 1 {
return Err(Error::IncorrectValidatorArity {
count: typed_fallback.arguments.len() as u32,
expected: 1,
location: typed_fallback.location,
});
}
for arg in typed_fallback.arguments.iter_mut() {
if arg.tipo.is_unbound() {
arg.tipo = builtins::data();
} }
}
Ok((typed_params, typed_fallback))
})?;
Ok(Definition::Validator(Validator { Ok(Definition::Validator(Validator {
doc, doc,