From 714c9b490e542aa53306582749c28cdb7f0d4085 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Fri, 5 Jan 2024 23:40:58 +0100 Subject: [PATCH] semantic: warn on variable shadowing --- compiler/semantic.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/semantic.py b/compiler/semantic.py index d7e3c40..db0ccbe 100644 --- a/compiler/semantic.py +++ b/compiler/semantic.py @@ -131,6 +131,11 @@ class Context: if name in self.variables: raise SemanticAnalysisError(value.location()) + upper_definition = self._get_symbol("variables", name) + if upper_definition is not None: + CompilationWarning(definition.location(), + f"Shadowing previous definition {upper_definition.definition.location()}").raise_warning() + typedef = self.get_type(type_identifier.value) if typedef is None: raise SemanticAnalysisError(location=type_identifier.location(),