amaranth icon indicating copy to clipboard operation
amaranth copied to clipboard

Emit a warning when matching a signal with an enum decoder with enum values of wrong type

Open Ravenslofty opened this issue 5 years ago • 2 comments

If you have x = Signal(decoder=Foo) and try to do x.match(Bar.QUUX) or m.Switch(x)/m.Case(Bar.QUUX), there should be an exception (TypeError?) thrown to catch any potential bugs where an enum of the wrong type is being used.

Ravenslofty avatar May 11 '20 15:05 Ravenslofty

We can do this on a best-effort basis with a lint (warning by default diagnostic), but Amaranth is an untyped language (in that all values belong to the same type and are mutually interoperable regardless of how they're constructed) and it is not feasible to add a type system to it even if it was desired.

whitequark avatar Jan 31 '23 14:01 whitequark

This doesn't change the language and so doesn't need an RFC, someone can just implement it. @Ravenslofty?

whitequark avatar Jan 31 '23 14:01 whitequark