Error when using a layout property outside of a layout

This commit is contained in:
Olivier Goffart 2020-07-28 18:24:36 +02:00
parent 5b2add75e4
commit 733f44f50b
3 changed files with 21 additions and 4 deletions

View file

@ -115,10 +115,12 @@ pub fn lower_layouts(component: &Rc<Component>, diag: &mut BuildDiagnostics) {
}); });
continue; continue;
} else { } else {
check_no_layout_properties(&child, diag);
elem.children.push(child); elem.children.push(child);
} }
} }
}); });
check_no_layout_properties(&component.root_element, diag);
} }
impl GridLayout { 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);
}
}
}

View file

@ -23,9 +23,14 @@ X := Rectangle {
Text{ Text{
row: 200000; // that's actually bigger than 65535 row: 200000; // that's actually bigger than 65535
// ^error{'row' must be a positive integer} // ^error{'row' must be a positive integer}
Rectangle { row: 3; }
// ^error{row used outside of a GridLayout}
} }
} }
colspan: 3; Text { colspan: 3; }
//FIXME: error{colspan used outside of a layout} // ^error{colspan used outside of a GridLayout}
col: 3;
// ^error{col used outside of a GridLayout}
} }

View file

@ -8,8 +8,10 @@
#[test] #[test]
fn syntax_tests() -> std::io::Result<()> { fn syntax_tests() -> std::io::Result<()> {
if let Some(specific_test) = if let Some(specific_test) = std::env::args()
std::env::args().skip(1).skip_while(|arg| arg.starts_with("--") || arg == "main").next() .skip(1)
.skip_while(|arg| arg.starts_with("--") || arg == "syntax_tests")
.next()
{ {
let mut path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); let mut path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("tests"); path.push("tests");