hdl.rec: fix Record.like() being called through a subclass.
authorwhitequark <cz@m-labs.hk>
Sat, 9 Nov 2019 16:44:01 +0000 (16:44 +0000)
committerwhitequark <cz@m-labs.hk>
Sat, 9 Nov 2019 17:45:07 +0000 (17:45 +0000)
The subclass does not necessarily take layout as the first argument.

nmigen/hdl/rec.py

index 58e1e85581d9c561864c2de2648a86e6c1439140..115fe17319b2394b33df17b1dafaac14ea3d5ec2 100644 (file)
@@ -83,8 +83,8 @@ class Layout:
 
 # Unlike most Values, Record *can* be subclassed.
 class Record(Value):
-    @classmethod
-    def like(cls, other, *, name=None, name_suffix=None, src_loc_at=0):
+    @staticmethod
+    def like(other, *, name=None, name_suffix=None, src_loc_at=0):
         if name is not None:
             new_name = str(name)
         elif name_suffix is not None:
@@ -107,7 +107,7 @@ class Record(Value):
                 fields[field_name] = Signal.like(field, name=concat(new_name, field_name),
                                                  src_loc_at=1 + src_loc_at)
 
-        return cls(other.layout, name=new_name, fields=fields, src_loc_at=1)
+        return Record(other.layout, name=new_name, fields=fields, src_loc_at=1)
 
     def __init__(self, layout, *, name=None, fields=None, src_loc_at=0):
         if name is None: