Browse Source

Fix #2987: `(nuint)(-3)` is not a compile-time constant.

pull/2993/head
Daniel Grunwald 2 years ago
parent
commit
3f09958922
  1. 5
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/NativeInts.cs
  2. 11
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs

5
ICSharpCode.Decompiler.Tests/TestCases/Pretty/NativeInts.cs

@ -206,6 +206,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return (nint)(0 - x); return (nint)(0 - x);
} }
public bool CompareToMinus3(nuint x)
{
return x == unchecked((nuint)(-3));
}
public nint SignedNotFittingIn32Bits() public nint SignedNotFittingIn32Bits()
{ {
// Explicit `unchecked` is necessary when casting oversized constant to nint // Explicit `unchecked` is necessary when casting oversized constant to nint

11
ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs

@ -1223,14 +1223,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
ResolveResult rr = ResolveCast(targetType, expression); ResolveResult rr = ResolveCast(targetType, expression);
if (rr.IsError) if (rr.IsError)
return rr; return rr;
Debug.Assert(rr.IsCompileTimeConstant); if (rr.IsCompileTimeConstant)
return new ConstantResolveResult(nullableType, rr.ConstantValue); return new ConstantResolveResult(nullableType, rr.ConstantValue);
}
else
{
return Convert(expression, nullableType,
isNullable ? Conversion.ImplicitNullableConversion : Conversion.ImplicitNumericConversion);
} }
return Convert(expression, nullableType,
isNullable ? Conversion.ImplicitNullableConversion : Conversion.ImplicitNumericConversion);
} }
#endregion #endregion

Loading…
Cancel
Save