@@ -2177,13 +2177,14 @@ def like(cls, other, *, name=None, name_suffix=None, init=None, reset=None, src_
2177
2177
2178
2178
Parameters
2179
2179
----------
2180
- other : Value
2180
+ other : ValueLike
2181
2181
Object to base this Signal on.
2182
2182
"""
2183
+ cast_other = Value .cast (other )
2183
2184
if name is not None :
2184
2185
new_name = str (name )
2185
2186
elif name_suffix is not None :
2186
- new_name = other .name + str (name_suffix )
2187
+ new_name = cast_other .name + str (name_suffix )
2187
2188
else :
2188
2189
new_name = tracer .get_var_name (depth = 2 + src_loc_at , default = "$like" )
2189
2190
# TODO(amaranth-0.7): remove
@@ -2196,11 +2197,15 @@ def like(cls, other, *, name=None, name_suffix=None, init=None, reset=None, src_
2196
2197
if isinstance (other , ValueCastable ):
2197
2198
shape = other .shape ()
2198
2199
else :
2199
- shape = Value . cast ( other ) .shape ()
2200
+ shape = cast_other .shape ()
2200
2201
kw = dict (shape = shape , name = new_name )
2201
- if isinstance (other , Signal ):
2202
- kw .update (init = other .init , reset_less = other .reset_less ,
2203
- attrs = other .attrs , decoder = other .decoder )
2202
+ if isinstance (cast_other , Signal ):
2203
+ if isinstance (shape , ShapeCastable ):
2204
+ other_init = shape .from_bits (cast_other .init )
2205
+ else :
2206
+ other_init = cast_other .init
2207
+ kw .update (init = other_init , reset_less = cast_other .reset_less ,
2208
+ attrs = cast_other .attrs , decoder = cast_other .decoder )
2204
2209
kw .update (kwargs )
2205
2210
if init is not None :
2206
2211
kw ["init" ] = init
0 commit comments