Skip to content

Commit

Permalink
core: Parse module correctly when allow-unregistered-dialect is set
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarice committed Dec 22, 2024
1 parent 42681e6 commit b5c51ea
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions xdsl/parser/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,16 +744,23 @@ def _get_op_by_name(self, name: str) -> type[Operation]:
Raises an error if the operation is not registered, and if unregistered
dialects are not allowed.
"""
from xdsl.dialects import builtin

op_type = self.ctx.get_optional_op(name)
if op_type is not None:

if op_type is not None and not issubclass(op_type, builtin.UnregisteredOp):
return op_type

for dialect_name in reversed(self._parser_state.dialect_stack):
op_type = self.ctx.get_optional_op(f"{dialect_name}.{name}")
if op_type is not None:
return op_type

self.raise_error(f"unregistered operation {name}!")
op_with_dialect_type = self.ctx.get_optional_op(f"{dialect_name}.{name}")
if op_with_dialect_type is not None and not issubclass(
op_with_dialect_type, builtin.UnregisteredOp
):
return op_with_dialect_type

if op_type is None:
self.raise_error(f"unregistered operation {name}!")
return op_type

def _parse_op_result(self) -> tuple[Span, int]:
"""
Expand Down

0 comments on commit b5c51ea

Please sign in to comment.