From: whitequark Date: Thu, 14 Feb 2019 20:52:42 +0000 (+0000) Subject: hdl.ir: raise a more descriptive error on non-elaboratable object. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=27b5e526a8de47c2d7f7824b84dad5cdaca528b5;p=nmigen.git hdl.ir: raise a more descriptive error on non-elaboratable object. --- diff --git a/nmigen/hdl/ir.py b/nmigen/hdl/ir.py index ac608e2..d799648 100644 --- a/nmigen/hdl/ir.py +++ b/nmigen/hdl/ir.py @@ -18,9 +18,13 @@ class Fragment: def get(obj, platform): if isinstance(obj, Fragment): return obj - if not hasattr(obj, "elaborate"): # :deprecated: - return Fragment.get(obj.get_fragment(platform), platform) - return Fragment.get(obj.elaborate(platform), platform) + if hasattr(obj, "elaborate"): + frag = obj.elaborate(platform) + elif hasattr(obj, "get_fragment"): # :deprecated: + frag = obj.get_fragment(platform) + else: + raise AttributeError("Object '{!r}' cannot be elaborated".format(obj)) + return Fragment.get(frag, platform) def __init__(self): self.ports = SignalDict() diff --git a/nmigen/test/test_hdl_ir.py b/nmigen/test/test_hdl_ir.py index e6158bb..4c59917 100644 --- a/nmigen/test/test_hdl_ir.py +++ b/nmigen/test/test_hdl_ir.py @@ -7,6 +7,13 @@ from ..hdl.mem import * from .tools import * +class FragmentGetTestCase(FHDLTestCase): + def test_get_wrong(self): + with self.assertRaises(AttributeError, + msg="Object 'None' cannot be elaborated"): + Fragment.get(None, platform=None) + + class FragmentGeneratedTestCase(FHDLTestCase): def test_find_subfragment(self): f1 = Fragment()