File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -240,8 +240,9 @@ def const(self, init):
240
240
key_value .shape ()))
241
241
elif not isinstance (key_value , Const ):
242
242
key_value = Const (key_value , cast_field_shape )
243
- int_value &= ~ (((1 << cast_field_shape .width ) - 1 ) << field .offset )
244
- int_value |= key_value .value << field .offset
243
+ mask = ((1 << cast_field_shape .width ) - 1 ) << field .offset
244
+ int_value &= ~ mask
245
+ int_value |= (key_value .value << field .offset ) & mask
245
246
return Const (int_value , self .as_shape ())
246
247
247
248
Original file line number Diff line number Diff line change @@ -398,6 +398,12 @@ def test_const(self):
398
398
self .assertRepr (fl .const ({"b" : 0b10 }), "(const 2'd2)" )
399
399
self .assertRepr (fl .const ({"a" : 0b1 , "b" : 0b10 }), "(const 2'd2)" )
400
400
401
+ sls = StructLayout ({
402
+ "a" : signed (4 ),
403
+ "b" : signed (4 )
404
+ })
405
+ self .assertRepr (sls .const ({"b" : 0 , "a" : - 1 }), "(const 8'd15)" )
406
+
401
407
def test_const_wrong (self ):
402
408
sl = StructLayout ({"f" : unsigned (1 )})
403
409
with self .assertRaisesRegex (TypeError ,
You can’t perform that action at this time.
0 commit comments