Skip to content

Commit df9343f

Browse files
committed
Reject interpolation property for non-angle animations
Instead of checking individual angle-* interpolation mode values, reject the `interpolation` property entirely when the animated property is not of type angle. This is simpler and more robust since it handles all expression forms, not just literal identifiers.
1 parent beb6204 commit df9343f

File tree

2 files changed

+16
-40
lines changed

2 files changed

+16
-40
lines changed

internal/compiler/object_tree.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,33 +2348,18 @@ fn animation_element_from_node(
23482348
);
23492349
None
23502350
} else {
2351-
// Check if angle-* interpolation mode is used with a non-angle property
2352-
for binding in anim.Binding() {
2353-
let Some(ident) = binding.child_token(SyntaxKind::Identifier) else { continue };
2354-
if parser::normalize_identifier(ident.text()) != "interpolation" {
2355-
continue;
2356-
}
2357-
// Check if the binding value is a simple identifier (QualifiedName)
2358-
let binding_expr = binding.BindingExpression();
2359-
let Some(expr) = binding_expr.Expression() else { continue };
2360-
let Some(qn) = expr.QualifiedName() else { continue };
2361-
let mode = qn.text().to_string();
2362-
let normalized_mode = parser::normalize_identifier(&mode);
2363-
// Check for angle-* interpolation modes
2364-
if matches!(
2365-
normalized_mode.as_str(),
2366-
"angle-shorter" | "angle-longer" | "angle-clockwise" | "angle-counterclockwise"
2367-
) && prop_type != Type::Angle
2368-
{
2369-
diag.push_error(
2370-
format!(
2371-
"The '{}' interpolation mode can only be used with angle properties, but '{}' has type {}",
2372-
mode.trim(),
2373-
prop_name.text().to_string().trim(),
2374-
prop_type
2375-
),
2376-
&qn,
2377-
);
2351+
// The `interpolation` property is only meaningful for angle properties
2352+
if prop_type != Type::Angle {
2353+
for binding in anim.Binding() {
2354+
let Some(ident) = binding.child_token(SyntaxKind::Identifier) else {
2355+
continue;
2356+
};
2357+
if parser::normalize_identifier(ident.text()) == "interpolation" {
2358+
diag.push_error(
2359+
"The 'interpolation' property is only allowed when animating angle properties".into(),
2360+
&ident,
2361+
);
2362+
}
23782363
}
23792364
}
23802365

internal/compiler/tests/syntax/basic/property_animation.slint

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,17 @@ export TestCase := Rectangle {
1111
// ^error{Unknown property x in PropertyAnimation}
1212
}
1313

14-
// Test: angle-* interpolation modes should only be used with angle properties
14+
// Test: interpolation property is rejected for non-angle properties
1515
animate width {
1616
interpolation: angle-shorter;
17-
// > <error{The 'angle-shorter' interpolation mode can only be used with angle properties, but 'width' has type length}
17+
// > <error{The 'interpolation' property is only allowed when animating angle properties}
1818
}
1919
animate height {
20-
interpolation: angle-longer;
21-
// > <error{The 'angle-longer' interpolation mode can only be used with angle properties, but 'height' has type length}
22-
}
23-
animate opacity {
24-
interpolation: angle-clockwise;
25-
// > <error{The 'angle-clockwise' interpolation mode can only be used with angle properties, but 'opacity' has type float}
26-
}
27-
28-
// Valid: linear interpolation can be used with any property type
29-
animate min-width {
3020
interpolation: linear;
21+
// > <error{The 'interpolation' property is only allowed when animating angle properties}
3122
}
3223

33-
// Valid: angle-* interpolation with angle properties
24+
// Valid: interpolation with angle properties
3425
property <angle> my-angle;
3526
animate my-angle {
3627
interpolation: angle-shorter;

0 commit comments

Comments
 (0)