Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# Metadata Int32 MinValue is wrong #29786

Closed
vsfeedback opened this issue Sep 11, 2018 · 7 comments · Fixed by #30742
Closed

C# Metadata Int32 MinValue is wrong #29786

vsfeedback opened this issue Sep 11, 2018 · 7 comments · Fixed by #30742
Assignees
Labels
Area-IDE Bug Developer Community The issue was originally reported on https://developercommunity.visualstudio.com Regression Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
Milestone

Comments

@vsfeedback
Copy link

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)

@sharwell sharwell added Bug Area-IDE Regression help wanted The issue is "up for grabs" - add a comment if you are interested in working on it Developer Community The issue was originally reported on https://developercommunity.visualstudio.com labels Sep 11, 2018
@sharwell sharwell added this to InQueue in Small Fixes Sep 12, 2018
@AdamSpeight2008
Copy link
Contributor

AdamSpeight2008 commented Sep 12, 2018

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

@sharwell
Copy link
Member

@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.

@CyrusNajmabadi
Copy link
Member

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.

@jinujoseph jinujoseph modified the milestones: 16.0, 16.0.P2 Sep 20, 2018
@jinujoseph jinujoseph added the 4 - In Review A fix for the issue is submitted for review. label Dec 6, 2018
@sharwell sharwell moved this from InQueue to In Review in Small Fixes Dec 6, 2018
@sharwell sharwell added Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented and removed 4 - In Review A fix for the issue is submitted for review. help wanted The issue is "up for grabs" - add a comment if you are interested in working on it labels Dec 11, 2018
@sharwell sharwell moved this from In Review to Current Sprint in Small Fixes Dec 11, 2018
@dmitry-lipetsk
Copy link

Visual Studio 2017 (15.9.11)

Same problem with Int64.MinValue

#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 :)

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

@svick
Copy link
Contributor

svick commented Apr 15, 2019

@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?

@dmitry-lipetsk
Copy link

@svick

Hm, you right :)

VS2019 shows Int64.MinValue correctly

#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<Int64>, IEquatable<Int64>
    {
        //
        // Сводка:
        //     Представляет наибольшее возможное значение типа Int64. Это поле является константой.
        public const Int64 MaxValue = 9223372036854775807;
        //
        // Сводка:
        //     Представляет наименьшее возможное значение типа Int64. Это поле является константой.
        public const Int64 MinValue = -9223372036854775808;

@TrevorBai

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug Developer Community The issue was originally reported on https://developercommunity.visualstudio.com Regression Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
Small Fixes
  
Completed
Development

Successfully merging a pull request may close this issue.

8 participants