diff --git a/artiq/compiler/builtins.py b/artiq/compiler/builtins.py index 4e4406925..8ca095b81 100644 --- a/artiq/compiler/builtins.py +++ b/artiq/compiler/builtins.py @@ -71,11 +71,11 @@ class TException(types.TMono): def __init__(self, name="Exception"): super().__init__(name) -class TIndexError(types.TMono): +class TIndexError(TException): def __init__(self): super().__init__("IndexError") -class TValueError(types.TMono): +class TValueError(TException): def __init__(self): super().__init__("ValueError") @@ -150,6 +150,9 @@ def is_range(typ, elt=None): else: return types.is_mono(typ, "range") +def is_exception(typ): + return isinstance(typ.find(), TException) + def is_iterable(typ): typ = typ.find() return isinstance(typ, types.TMono) and \ @@ -157,7 +160,7 @@ def is_iterable(typ): def get_iterable_elt(typ): if is_iterable(typ): - return typ.find()["elt"] + return typ.find()["elt"].find() def is_collection(typ): typ = typ.find() diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index 3db7e12c0..2e34c4e57 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -827,7 +827,7 @@ class Inferencer(algorithm.Visitor): {"typeb": printer.name(typeb)}, locb) ] - self._unify(node.name_type, node.filter.type.to_exception_type(), + self._unify(node.name_type, builtins.TException(node.filter.type.name), node.name_loc, node.filter.loc, makenotes) def _type_from_arguments(self, node, ret): diff --git a/artiq/compiler/types.py b/artiq/compiler/types.py index 4b6dd9a55..b29eb513e 100644 --- a/artiq/compiler/types.py +++ b/artiq/compiler/types.py @@ -268,9 +268,6 @@ class TExceptionConstructor(TBuiltin): Note that this is not the same as the type of an instance of the class, which is ``TMono("Exception", ...)``. """ - def to_exception_type(self): - # Exceptions currently can't have type parameters - return TMono(self.name, {}) class TValue(Type): """