From 42a4286048664ddddb4fc44b8670a80feca857f0 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 22 Mar 2024 14:00:12 +0100 Subject: [PATCH] Fix missing error when calling argb() with too many arguments This is technically a breaking change if someone was calling it with too many args by mistake, but i think it's fine to do this as a bugfix --- internal/compiler/builtin_macros.rs | 7 +++++-- internal/compiler/tests/syntax/lookup/color.slint | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/compiler/builtin_macros.rs b/internal/compiler/builtin_macros.rs index 7cd8e161258..8da9ffa3ab0 100644 --- a/internal/compiler/builtin_macros.rs +++ b/internal/compiler/builtin_macros.rs @@ -187,8 +187,11 @@ fn rgb_macro( args: Vec<(Expression, Option)>, diag: &mut BuildDiagnostics, ) -> Expression { - if args.len() < 3 { - diag.push_error("Needs 3 or 4 argument".into(), &node); + if args.len() < 3 || args.len() > 4 { + diag.push_error( + format!("This function needs 3 or 4 arguments, but {} were provided", args.len()), + &node, + ); return Expression::Invalid; } let mut arguments: Vec<_> = args diff --git a/internal/compiler/tests/syntax/lookup/color.slint b/internal/compiler/tests/syntax/lookup/color.slint index dc5bd8e38bc..70265e21cb2 100644 --- a/internal/compiler/tests/syntax/lookup/color.slint +++ b/internal/compiler/tests/syntax/lookup/color.slint @@ -38,5 +38,17 @@ export X := Rectangle { // ^error{Cannot take reference to a namespace} property xxx: Colors.xxx; // ^error{'xxx' is not a member of the namespace Colors} + + property c1: rgba(); +// ^error{This function needs 3 or 4 arguments, but 0 were provided} + property c2: rgb(45); +// ^error{This function needs 3 or 4 arguments, but 1 were provided} + property c3: Colors.rgb(45,45); +// ^error{This function needs 3 or 4 arguments, but 2 were provided} + property c4: Colors.rgba(1,2,3,4,5); +// ^error{This function needs 3 or 4 arguments, but 5 were provided} + + } + }