Skip to content

Commit cf51367

Browse files
committed
compiler: Improve diagnostics when using layout properties
Clarify that for example rowspan and colspan are to be used in a cell. Case in point: ``` GridLayout { rowspan: 2; ``` shouldn't say that "rowspan" can't be used in a GridLayout when it's used in a grid layout :)
1 parent a11efb7 commit cf51367

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

internal/compiler/passes/lower_layout.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,12 +856,15 @@ fn check_no_layout_properties(
856856
if parent_layout_type.as_deref() != Some("GridLayout")
857857
&& matches!(prop.as_ref(), "col" | "row" | "colspan" | "rowspan")
858858
{
859-
diag.push_error(format!("{prop} used outside of a GridLayout"), &*expr.borrow());
859+
diag.push_error(format!("{prop} used outside of a GridLayout's cell"), &*expr.borrow());
860860
}
861861
if parent_layout_type.as_deref() != Some("Dialog")
862862
&& matches!(prop.as_ref(), "dialog-button-role")
863863
{
864-
diag.push_error(format!("{prop} used outside of a Dialog"), &*expr.borrow());
864+
diag.push_error(
865+
format!("{prop} used outside of a Dialog's direct child"),
866+
&*expr.borrow(),
867+
);
865868
}
866869
if layout_type.is_none()
867870
&& matches!(

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ MyDiag2 := Dialog {
1818
StandardButton {
1919
kind: cancel;
2020
col: 42;
21-
// ^error{col used outside of a GridLayout}
21+
// ^error{col used outside of a GridLayout's cell}
2222
rowspan: 2;
23-
// ^error{rowspan used outside of a GridLayout}
23+
// ^error{rowspan used outside of a GridLayout's cell}
2424
}
2525
}
2626

@@ -47,7 +47,7 @@ MyDialog4 := Dialog {
4747
// ^error{The `dialog-button-role` property must be known at compile-time}
4848
Rectangle {
4949
Rectangle { dialog-button-role: accept; }
50-
// ^error{dialog-button-role used outside of a Dialog}
50+
// ^error{dialog-button-role used outside of a Dialog's direct child}
5151
}
5252

5353
init => {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ export X := Rectangle {
4141
row: 200000; // that's actually bigger than 65535
4242
// ^error{'row' must be a positive integer}
4343
Rectangle { row: 3; }
44-
// ^error{row used outside of a GridLayout}
44+
// ^error{row used outside of a GridLayout's cell}
4545
}
4646
}
4747

4848
Text { colspan: 3; }
49-
// ^error{colspan used outside of a GridLayout}
49+
// ^error{colspan used outside of a GridLayout's cell}
5050
col: 3;
51-
// ^error{col used outside of a GridLayout}
51+
// ^error{col used outside of a GridLayout's cell}
5252

5353
HorizontalLayout {
5454
col: 3;
55-
// ^error{col used outside of a GridLayout}
55+
// ^error{col used outside of a GridLayout's cell}
5656
}
5757
}

0 commit comments

Comments
 (0)