diff --git a/midas/checker/midas.py b/midas/checker/midas.py index 452f9c1..8d9b7ec 100644 --- a/midas/checker/midas.py +++ b/midas/checker/midas.py @@ -207,6 +207,7 @@ class MidasTyper(m.Stmt.Visitor[None], m.Expr.Visitor[Type], m.Type.Visitor[Type ) def visit_predicate_stmt(self, stmt: m.PredicateStmt) -> None: + name: str = stmt.name.lexeme for spec in stmt.params: for param in spec.mixed: assert param.name is not None @@ -228,14 +229,17 @@ class MidasTyper(m.Stmt.Visitor[None], m.Expr.Visitor[Type], m.Type.Visitor[Type returns=type, ) self._predicate_params = {} - self.types.define_predicate( - stmt.name.lexeme, - Predicate( - type=type, - body=stmt.body, - alias=len(params) == 0, - ), - ) + try: + self.types.define_predicate( + name, + Predicate( + type=type, + body=stmt.body, + alias=len(params) == 0, + ), + ) + except ValueError: + self.reporter.error(stmt.location, f"Predicate {name} already defined") def _is_valid_predicate(self, body: Type) -> bool: """Check whether the given type is valid as a predicate's body