Show error when trying to export at non-top-level (#7110)
This commit is contained in:
@ -281,7 +281,14 @@ impl ExecutorContext {
|
||||
|
||||
// Track exports.
|
||||
if let ItemVisibility::Export = variable_declaration.visibility {
|
||||
exec_state.mod_local.module_exports.push(var_name);
|
||||
if matches!(body_type, BodyType::Root) {
|
||||
exec_state.mod_local.module_exports.push(var_name);
|
||||
} else {
|
||||
exec_state.err(CompilationError::err(
|
||||
variable_declaration.as_source_range(),
|
||||
"Exports are only supported at the top-level of a file. Remove `export` or move it to the top-level.",
|
||||
));
|
||||
}
|
||||
}
|
||||
// Variable declaration can be the return value of a module.
|
||||
last_expr = matches!(body_type, BodyType::Root).then_some(value);
|
||||
|
@ -1185,6 +1185,27 @@ mod import_foreign {
|
||||
super::execute(TEST_NAME, false).await
|
||||
}
|
||||
}
|
||||
mod export_var_only_at_top_level {
|
||||
const TEST_NAME: &str = "export_var_only_at_top_level";
|
||||
|
||||
/// Test parsing KCL.
|
||||
#[test]
|
||||
fn parse() {
|
||||
super::parse(TEST_NAME)
|
||||
}
|
||||
|
||||
/// Test that parsing and unparsing KCL produces the original KCL input.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn unparse() {
|
||||
super::unparse(TEST_NAME).await
|
||||
}
|
||||
|
||||
/// Test that KCL is executed correctly.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn kcl_test_execute() {
|
||||
super::execute(TEST_NAME, false).await
|
||||
}
|
||||
}
|
||||
mod assembly_non_default_units {
|
||||
const TEST_NAME: &str = "assembly_non_default_units";
|
||||
|
||||
|
Reference in New Issue
Block a user