From 733f44f50b38edaee8affe9a9f6691243ed71bcd Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 28 Jul 2020 18:24:36 +0200 Subject: [PATCH] Error when using a layout property outside of a layout --- sixtyfps_compiler/passes/lower_layout.rs | 10 ++++++++++ sixtyfps_compiler/tests/syntax/basic/layout2.60 | 9 +++++++-- sixtyfps_compiler/tests/syntax_tests.rs | 6 ++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sixtyfps_compiler/passes/lower_layout.rs b/sixtyfps_compiler/passes/lower_layout.rs index 8884c294f..3d1b272be 100644 --- a/sixtyfps_compiler/passes/lower_layout.rs +++ b/sixtyfps_compiler/passes/lower_layout.rs @@ -115,10 +115,12 @@ pub fn lower_layouts(component: &Rc, diag: &mut BuildDiagnostics) { }); continue; } else { + check_no_layout_properties(&child, diag); elem.children.push(child); } } }); + check_no_layout_properties(&component.root_element, diag); } impl GridLayout { @@ -170,3 +172,11 @@ fn eval_const_expr( } } } + +fn check_no_layout_properties(item: &ElementRc, diag: &mut BuildDiagnostics) { + for (prop, expr) in item.borrow().bindings.iter() { + if matches!(prop.as_ref(), "col" | "row" | "colspan" | "rowspan") { + diag.push_error(format!("{} used outside of a GridLayout", prop), expr); + } + } +} diff --git a/sixtyfps_compiler/tests/syntax/basic/layout2.60 b/sixtyfps_compiler/tests/syntax/basic/layout2.60 index 2f9bae579..c585775c5 100644 --- a/sixtyfps_compiler/tests/syntax/basic/layout2.60 +++ b/sixtyfps_compiler/tests/syntax/basic/layout2.60 @@ -23,9 +23,14 @@ X := Rectangle { Text{ row: 200000; // that's actually bigger than 65535 // ^error{'row' must be a positive integer} + Rectangle { row: 3; } +// ^error{row used outside of a GridLayout} } } - colspan: 3; -//FIXME: error{colspan used outside of a layout} + Text { colspan: 3; } +// ^error{colspan used outside of a GridLayout} + col: 3; +// ^error{col used outside of a GridLayout} + } \ No newline at end of file diff --git a/sixtyfps_compiler/tests/syntax_tests.rs b/sixtyfps_compiler/tests/syntax_tests.rs index 882953cb7..c4187b1bd 100644 --- a/sixtyfps_compiler/tests/syntax_tests.rs +++ b/sixtyfps_compiler/tests/syntax_tests.rs @@ -8,8 +8,10 @@ #[test] fn syntax_tests() -> std::io::Result<()> { - if let Some(specific_test) = - std::env::args().skip(1).skip_while(|arg| arg.starts_with("--") || arg == "main").next() + if let Some(specific_test) = std::env::args() + .skip(1) + .skip_while(|arg| arg.starts_with("--") || arg == "syntax_tests") + .next() { let mut path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); path.push("tests");