Skip to content

Commit

Permalink
Improved support for f32 unifying types
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Nov 1, 2024
1 parent f3aa9bf commit 0386a1c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/resolve/unify_types/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,19 @@ pub fn compute_unifying_type(
}

// If all values are integer and floating literals, use the default floating-point type
// NOTE: TODO: Handle case when `f32` is the preferred type?
if types_iter.clone().all(|resolved_type| {
matches!(
resolved_type.kind,
TypeKind::IntegerLiteral(..) | TypeKind::FloatLiteral(..)
)
}) {
return Some(TypeKind::Floating(FloatSize::Bits64).at(source));
if let Some(TypeKind::Floating(FloatSize::Bits32)) =
preferred_type.as_ref().map(|ty| &ty.kind)
{
return Some(TypeKind::Floating(FloatSize::Bits32).at(source));
} else {
return Some(TypeKind::Floating(FloatSize::Bits64).at(source));
}
}

// If all values are integers and integer literals
Expand Down

0 comments on commit 0386a1c

Please sign in to comment.