semantic: warn on variable shadowing

This commit is contained in:
Antoine Viallon 2024-01-05 23:40:58 +01:00
parent 1bf549eda4
commit 714c9b490e
Signed by: aviallon
GPG key ID: 186FC35EDEB25716

View file

@ -131,6 +131,11 @@ class Context:
if name in self.variables: if name in self.variables:
raise SemanticAnalysisError(value.location()) 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) typedef = self.get_type(type_identifier.value)
if typedef is None: if typedef is None:
raise SemanticAnalysisError(location=type_identifier.location(), raise SemanticAnalysisError(location=type_identifier.location(),