Skip to content

Commit 67c1c30

Browse files
committed
Do not allow redeclaration in global scope
1 parent 11e44cb commit 67c1c30

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4921,17 +4921,13 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
49214921

49224922
if (current_scope->get_scope().find(var_name) !=
49234923
current_scope->get_scope().end()) {
4924-
if (current_scope->parent != nullptr) {
4925-
// Re-declaring a global scope variable is allowed,
4926-
// otherwise raise an error
4927-
ASR::symbol_t *orig_decl = current_scope->get_symbol(var_name);
4928-
throw SemanticError(diag::Diagnostic(
4929-
"Symbol is already declared in the same scope",
4930-
diag::Level::Error, diag::Stage::Semantic, {
4931-
diag::Label("original declaration", {orig_decl->base.loc}, false),
4932-
diag::Label("redeclaration", {x.base.base.loc}),
4933-
}));
4934-
}
4924+
ASR::symbol_t *orig_decl = current_scope->get_symbol(var_name);
4925+
throw SemanticError(diag::Diagnostic(
4926+
"Symbol is already declared in the same scope",
4927+
diag::Level::Error, diag::Stage::Semantic, {
4928+
diag::Label("original declaration", {orig_decl->base.loc}, false),
4929+
diag::Label("redeclaration", {x.base.base.loc}),
4930+
}));
49354931
}
49364932
ASR::expr_t *init_expr = nullptr;
49374933
visit_AnnAssignUtil(x, var_name, init_expr);

0 commit comments

Comments
 (0)