VS 2017 Bug 或新功能?

VS 2017 Bug or new features?

升级到 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;
    }

异常:

Error 1: The variable 'i' cannot be used with type arguments
Error 2: 'hex' is a variable but is used like a type    

解决方案是用括号将表达式括起来。

for (int i = 0; i < (hex.Length >> 1); ++i)

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

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

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