fix(checker): handle already defined predicates
This commit is contained in:
@@ -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:
|
def visit_predicate_stmt(self, stmt: m.PredicateStmt) -> None:
|
||||||
|
name: str = stmt.name.lexeme
|
||||||
for spec in stmt.params:
|
for spec in stmt.params:
|
||||||
for param in spec.mixed:
|
for param in spec.mixed:
|
||||||
assert param.name is not None
|
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,
|
returns=type,
|
||||||
)
|
)
|
||||||
self._predicate_params = {}
|
self._predicate_params = {}
|
||||||
|
try:
|
||||||
self.types.define_predicate(
|
self.types.define_predicate(
|
||||||
stmt.name.lexeme,
|
name,
|
||||||
Predicate(
|
Predicate(
|
||||||
type=type,
|
type=type,
|
||||||
body=stmt.body,
|
body=stmt.body,
|
||||||
alias=len(params) == 0,
|
alias=len(params) == 0,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
except ValueError:
|
||||||
|
self.reporter.error(stmt.location, f"Predicate {name} already defined")
|
||||||
|
|
||||||
def _is_valid_predicate(self, body: Type) -> bool:
|
def _is_valid_predicate(self, body: Type) -> bool:
|
||||||
"""Check whether the given type is valid as a predicate's body
|
"""Check whether the given type is valid as a predicate's body
|
||||||
|
|||||||
Reference in New Issue
Block a user