nodes: make some obvious dead-code raise a log message (Info)

This commit is contained in:
Antoine Viallon 2024-01-11 00:06:06 +01:00
parent 7106e400aa
commit 46c7907165
Signed by: aviallon
GPG key ID: 186FC35EDEB25716

View file

@ -5,7 +5,7 @@ from abc import abstractmethod, ABC
from typing import Any, Iterable from typing import Any, Iterable
from . import ir, semantic, lexer from . import ir, semantic, lexer
from .errors import SemanticAnalysisError, OverrideMandatoryError from .errors import SemanticAnalysisError, OverrideMandatoryError, CompilationWarning, Levels
from .logger import Logger from .logger import Logger
from .source import SourceLocation from .source import SourceLocation
from .typechecking import typecheck from .typechecking import typecheck
@ -291,8 +291,13 @@ class Block(Statement):
def intermediate_representation(self) -> list[ir.IRItem]: def intermediate_representation(self) -> list[ir.IRItem]:
result: list[ir.IRItem] = [] result: list[ir.IRItem] = []
for node in self.nodes: for node in self.nodes:
if not node.pure: if node.pure:
result += node.intermediate_representation() CompilationWarning(node.location(),
f"{node.__class__.__name__} ignored as it doesn't have any "
f"visible side effect.",
level=Levels.Info).raise_warning()
continue
result += node.intermediate_representation()
return result return result
def semantic_analysis(self, context: semantic.Context | None): def semantic_analysis(self, context: semantic.Context | None):