slint/internal/compiler/tests/syntax/basic/for_range.slint
Olivier Goffart b77368f1b6
diagnostic: try to detect use of range expression and recommand to use number
Several users have been asking if it is possible to use range
expression.
Detect this and have a meaningful error message
2025-04-19 22:47:45 +02:00

22 lines
879 B
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
export component Foo {
in property <int> count;
for x in 0..count: Rectangle { }
// ^error{Cannot access the field 'count' of float. Range expressions are not supported in Slint, but you can use an integer as a model to repeat something multiple time. Eg: `for i in count`}
// In these case, we should not suggest to use a model with a count
property <float> invalid: 0..count;
// ^error{Cannot access the field 'count' of float$}
for x in invalid.count: Rectangle { }
// ^error{Cannot access the field 'count' of float$}
for x in 0.px.count: Rectangle { }
// ^error{Cannot access the field 'count' of length$}
}