From: whitequark <whitequark@whitequark.org>
Date: Sat, 9 Nov 2019 16:44:01 +0000 (+0000)
Subject: hdl.rec: fix Record.like() being called through a subclass.
X-Git-Tag: v0.1
X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f8f7d8312773a852c6d6d91f99d8147add131d55;p=nmigen.git

hdl.rec: fix Record.like() being called through a subclass.

The subclass does not necessarily take layout as the first argument.
---

diff --git a/nmigen/hdl/rec.py b/nmigen/hdl/rec.py
index 58e1e85..115fe17 100644
--- a/nmigen/hdl/rec.py
+++ b/nmigen/hdl/rec.py
@@ -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: