Add more defaulting

This commit is contained in:
2024-04-15 15:28:06 -07:00
parent f915db9337
commit 3d8e0804bc
5 changed files with 28 additions and 6 deletions

View File

@@ -847,22 +847,39 @@ pub fn solve_constraints(
if !changed_something {
let mut addendums = vec![];
new_constraints.retain(|x| {
if let Constraint::ConstantNumericType(loc, t) = x {
macro_rules! default_type {
($addendums: ident, $loc: ident, $t: ident) => {
let resty = TypeOrVar::Primitive(PrimitiveType::U64);
addendums.push(Constraint::Equivalent(
loc.clone(),
t.clone(),
$addendums.push(Constraint::Equivalent(
$loc.clone(),
$t.clone(),
resty.clone(),
));
warnings.push(TypeInferenceWarning::DefaultedTo(loc.clone(), resty));
warnings.push(TypeInferenceWarning::DefaultedTo($loc.clone(), resty));
tracing::trace!("Adding number equivalence");
};
}
new_constraints.retain(|x| {
if let Constraint::ConstantNumericType(loc, t) = x {
default_type!(addendums, loc, t);
false
} else {
true
}
});
if addendums.is_empty() {
new_constraints.retain(|x| {
if let Constraint::IsSomething(loc, t) = x {
default_type!(addendums, loc, t);
false
} else {
true
}
});
}
if addendums.is_empty() {
if errors.is_empty() {
errors = new_constraints