Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError with strange Switch #305

nmigen-issue-migration opened this issue Jan 13, 2020 · 0 comments

AssertionError with strange Switch #305

nmigen-issue-migration opened this issue Jan 13, 2020 · 0 comments


Copy link

Issue by ZirconiumX
Monday Jan 13, 2020 at 20:31 GMT
Originally opened as m-labs/nmigen#305

from enum import Enum

from nmigen import *
from nmigen.back import verilog

class Piece(Enum):
    BISHOP = 2 # Has to be specifically > 1 to crash

class Square(Elaboratable):
    def __init__(self):
        self.i_piece = Signal(1)

    def elaborate(self, platform):
        m = Module()

        with m.Switch(self.i_piece):
            with m.Case(Piece.BISHOP): # Has to be this enum; inlining the value of 2 works fine

        return m

sq = Square()

print(verilog.convert(sq, ports=[sq.i_piece]))

This produces:

Traceback (most recent call last):
  File "", line 27, in <module>
    print(verilog.convert(sq, ports=[sq.i_piece]))
  File "/usr/local/lib/python3.7/dist-packages/nmigen-0.2.dev17+ge18385b-py3.7.egg/nmigen/back/", line 76, in convert
    rtlil_text = rtlil.convert(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/nmigen-0.2.dev17+ge18385b-py3.7.egg/nmigen/back/", line 1010, in convert
    fragment = ir.Fragment.get(elaboratable, platform).prepare(**kwargs)
  File "/usr/local/lib/python3.7/dist-packages/nmigen-0.2.dev17+ge18385b-py3.7.egg/nmigen/hdl/", line 67, in get       obj = obj.elaborate(platform)
  File "", line 20, in elaborate
  File "/usr/lib/python3.7/", line 119, in __exit__
  File "/usr/local/lib/python3.7/dist-packages/nmigen-0.2.dev17+ge18385b-py3.7.egg/nmigen/hdl/", line 264, in Switch
  File "/usr/local/lib/python3.7/dist-packages/nmigen-0.2.dev17+ge18385b-py3.7.egg/nmigen/hdl/", line 405, in _pop_ctrl
    src_loc=src_loc, case_src_locs=switch_case_src_locs))
  File "/usr/local/lib/python3.7/dist-packages/nmigen-0.2.dev17+ge18385b-py3.7.egg/nmigen/hdl/", line 1296, in __init__
    assert len(key) == len(self.test)

It minimised very oddly, but this is the smallest I could get it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

No branches or pull requests

1 participant