File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -328,6 +328,8 @@ def Case(self, *patterns):
328328 "expression, not {!r}"
329329 .format (pattern )) from e
330330 pattern_len = bits_for (pattern .value )
331+ if pattern .value == 0 :
332+ pattern_len = 0
331333 if pattern_len > len (switch_data ["test" ]):
332334 warnings .warn ("Case pattern '{!r}' ({}'{:b}) is wider than switch value "
333335 "(which has width {}); comparison will never be true"
Original file line number Diff line number Diff line change @@ -502,6 +502,21 @@ class Color(Enum):
502502 m .d .comb += dummy .eq (0 )
503503 self .assertEqual (m ._statements , {})
504504
505+ def test_Switch_zero_width (self ):
506+ m = Module ()
507+ s = Signal (0 )
508+ with m .Switch (s ):
509+ with m .Case (0 ):
510+ m .d .comb += self .c1 .eq (1 )
511+ m ._flush ()
512+ self .assertRepr (m ._statements ["comb" ], """
513+ (
514+ (switch (sig s)
515+ (case (eq (sig c1) (const 1'd1)))
516+ )
517+ )
518+ """ )
519+
505520 def test_Case_bits_wrong (self ):
506521 m = Module ()
507522 with m .Switch (self .w1 ):
You can’t perform that action at this time.
0 commit comments