VS 2017 Bug或新功能?

Mhd*_*een 24 c# roslyn c#-7.0

升级到VS 2017后,我从此代码中得到以下错误(一直运行良好)

byte[] HexStringToByteArray(string hex)
    {
        if (hex.Length % 2 == 1)
            throw new Exception("The binary key cannot have an odd number of digits");

        byte[] arr = new byte[hex.Length >> 1];

        for (int i = 0; i < hex.Length >> 1; ++i) // Error in this line
        {
            arr[i] = (byte)((GetHexVal(hex[i << 1]) << 4) + (GetHexVal(hex[(i << 1) + 1])));
        }

        return arr;
    }
Run Code Online (Sandbox Code Playgroud)

例外:

Error 1: The variable 'i' cannot be used with type arguments
Error 2: 'hex' is a variable but is used like a type    
Run Code Online (Sandbox Code Playgroud)

解决方案是用括号括起表达式.

for (int i = 0; i < (hex.Length >> 1); ++i)
Run Code Online (Sandbox Code Playgroud)

但这让我想知道这是一个错误还是一个新功能?谢谢.

Jul*_*eur 3

感谢您报告此事。这是解析优先级的确认回归。此修复最迟将在 VS2017 的第一季度版本中发布。

有关修复的信息:https://github.com/dotnet/roslyn/pull/16834