LibWeb: Correctly compute consistent type when simplifying hypot

Previously we would never get a valid `consistent_type` as we were
trying to make the node types consistent with the initial empty type
which isn't possible.

Gains us 7 WPT tests.
This commit is contained in:
Callum Law 2025-06-28 18:41:29 +12:00 committed by Andreas Kling
commit 8e9753eadb
Notes: github-actions[bot] 2025-06-30 12:54:14 +00:00
5 changed files with 261 additions and 4 deletions

View file

@ -2096,7 +2096,7 @@ Optional<CalculatedStyleValue::CalculationResult> HypotCalculationNode::run_oper
// <percentage>, but must have a consistent type or else the function is invalid; the results type will be the
// consistent type.
CSSNumericType consistent_type;
Optional<CSSNumericType> consistent_type;
double value = 0;
for (auto const& child : m_values) {
@ -2104,14 +2104,20 @@ Optional<CalculatedStyleValue::CalculationResult> HypotCalculationNode::run_oper
if (!canonical_child.has_value())
return {};
auto maybe_type = consistent_type.consistent_type(canonical_child->type().value());
if (!maybe_type.has_value())
if (!consistent_type.has_value())
consistent_type = canonical_child->type();
else
consistent_type = consistent_type->consistent_type(canonical_child->type().value());
if (!consistent_type.has_value())
return {};
consistent_type = maybe_type.release_value();
value += canonical_child->value() * canonical_child->value();
}
if (!consistent_type.has_value())
return {};
return CalculatedStyleValue::CalculationResult { sqrt(value), consistent_type };
}