Closed
Description
Description
runtime/src/libraries/System.Private.CoreLib/src/System/Byte.cs
Lines 1117 to 1124 in 0f0981f
Reproduction Steps
using System;
using System.Numerics;
BinaryIntegerWrapper<byte> a = new(2);
Console.WriteLine((a << 11).Value);
public struct BinaryIntegerWrapper<T> : IShiftOperators<BinaryIntegerWrapper<T>, int, BinaryIntegerWrapper<T>>
where T : IBinaryInteger<T>
{
public T Value;
public BinaryIntegerWrapper(T value) => Value = value;
public static implicit operator BinaryIntegerWrapper<T>(T value) => new BinaryIntegerWrapper<T>(value);
public static BinaryIntegerWrapper<T> operator <<(BinaryIntegerWrapper<T> value, int shiftAmount) => value.Value << shiftAmount;
public static BinaryIntegerWrapper<T> operator >>(BinaryIntegerWrapper<T> value, int shiftAmount) => value.Value >> shiftAmount;
public static BinaryIntegerWrapper<T> operator >>>(BinaryIntegerWrapper<T> value, int shiftAmount) => value.Value >>> shiftAmount;
}
Expected behavior
16
Actual behavior
0
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
Per this comment from @tannergooding:
This is also notably an issue with
sbyte
,short
, andushort
. It is also, unfortunately, a breaking change and will need a bar check.The intent had indeed been to correctly mask, which is being done in other operations but was missed for these ones.