Roslyn: C# Metadata Int32 MinValue is wrong

Created on 11 Sep 2018  ·  6Comments  ·  Source: dotnet/roslyn

public const Int32 MinValue = --2147483648;

-- ???? It will not compile ...

Visual Studio 15.8.2 ...

_This issue has been moved from https://developercommunity.visualstudio.com/content/problem/328206/c-metadata-int32-minvalue-is-wrong.html
VSTS ticketId: 677394_
_These are the original issue comments:_

BJ Myers on 9/11/2018, 04:25 PM (25 min ago): Reproduced in Visual Studio 15.8.4.
_These are the original issue solutions:_
(no solutions)

Area-IDE Bug Developer Community Regression Resolution-Fixed

All 6 comments

You are tryinging to decrement a constant value.
If the decrement operator didn't exist then the expression --2147783648 is equivalent to -(-2147783648) which should the value 2147783648 exceeds the Int32.MaxValue by 1.
If is unchecked i think it would return -1.

@sharwell

@AdamSpeight2008 Starting in 15.8, if you press F12 to navigate to Metadata as Source for System.Int32, you'll see MinValue defined with double-negation.

This is probably a bug i introduced when i fixed up how literals were converted to syntax nodes. There was probably some special casing here that added a - sign. And once the underlying helper was fixed we got double negation.

Visual Studio 2017 (15.9.11)

Same problem with Int64.MinValue

```c#

region Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2\mscorlib.dll

endregion

    //
    // Summary:
    //     Represents the smallest possible value of an Int64. This field is constant.
    public const Int64 MinValue = --9223372036854775808;

The problem with Int32.MinValue exists also :)

```c#
        //
        // Summary:
        //     Represents the smallest possible value of System.Int32. This field is constant.
        public const Int32 MinValue = --2147483648;

@dmitry-lipetsk The milestone for this issue is 16.0. I believe that means you can't expect for it to be fixed in VS 2017, you'll have to upgrade to VS 2019. Have you tried that?

@svick

Hm, you right :)

VS2019 shows Int64.MinValue correctly

```c#

region сборка mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2\mscorlib.dll

endregion

using System.Globalization;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;

namespace System
{
//
// Сводка:
// Представляет 64-разрядное целое число со знаком.
[ComVisible(true)]
public struct Int64 : IComparable, IFormattable, IConvertible, IComparable, IEquatable
{
//
// Сводка:
// Представляет наибольшее возможное значение типа Int64. Это поле является константой.
public const Int64 MaxValue = 9223372036854775807;
//
// Сводка:
// Представляет наименьшее возможное значение типа Int64. Это поле является константой.
public const Int64 MinValue = -9223372036854775808;

```

Was this page helpful?
0 / 5 - 0 ratings