mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
compiler: Warn user when immediately converting gradient macro to color (#6956)
Fixes #6819
This commit is contained in:
parent
35e094e723
commit
e4b70efe6e
3 changed files with 13 additions and 0 deletions
|
@ -1107,6 +1107,14 @@ impl Expression {
|
|||
self
|
||||
} else if ty.can_convert(&target_type) {
|
||||
let from = match (ty, &target_type) {
|
||||
(Type::Brush, Type::Color) => match self {
|
||||
Expression::LinearGradient { .. } | Expression::RadialGradient { .. } => {
|
||||
let message = format!("Narrowing conversion from {0} to {1}. This can lead to unexpected behavior because the {0} is a gradient", Type::Brush, Type::Color);
|
||||
diag.push_warning(message, node);
|
||||
self
|
||||
}
|
||||
_ => self,
|
||||
},
|
||||
(Type::Percent, Type::Float32) => Expression::BinaryExpression {
|
||||
lhs: Box::new(self),
|
||||
rhs: Box::new(Expression::NumberLiteral(0.01, Unit::None)),
|
||||
|
|
|
@ -29,4 +29,6 @@ export X := Rectangle {
|
|||
// ^error{Unknown unqualified identifier 'r'}
|
||||
property <brush> g15: @linear-gradient(90deg, brown o, green); // #3241
|
||||
// ^error{Unknown unqualified identifier 'o'}
|
||||
property<color> g16: @linear-gradient(0deg, red, green, blue); // #6819
|
||||
// ^warning{Narrowing conversion from brush to color. This can lead to unexpected behavior because the brush is a gradient}
|
||||
}
|
||||
|
|
|
@ -25,4 +25,7 @@ export X := Rectangle {
|
|||
property<brush> g11: @radial-gradient(circle,);
|
||||
|
||||
property<brush> g12: @radial-gradient(circle);
|
||||
|
||||
property<color> g13: @radial-gradient(circle, red, green, blue); // #6819
|
||||
// ^warning{Narrowing conversion from brush to color. This can lead to unexpected behavior because the brush is a gradient}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue