Roslyn: The C# compiler failed to compile "obj is byte*[]" form

Created on 9 Nov 2017  路  2Comments  路  Source: dotnet/roslyn

Version Used:
Visual Studio 2017
C#7.1
.NET Framework 4.7

Steps to Reproduce:

  1. Try to compile this code:
    C# namespace Test { static unsafe class Program { static void Main() { object obj = new byte*[10]; bool b = obj is byte*[]; } } }

Expected Behavior:
Compile success.

Actual Behavior:
Program.cs(8,20,8,24): error CS1525: Invalid expression term 'byte'
Program.cs(8,25,8,26): error CS1525: Invalid expression term '['
Program.cs(8,26,8,27): error CS0443: Syntax error; value expected

Area-Compilers Bug

Most helpful comment

The is operator doesn't work with pointers. I believe that limitation is inherited from the CLR isinst opcode not being able to distinguish between different pointer types.

All 2 comments

The is operator doesn't work with pointers. I believe that limitation is inherited from the CLR isinst opcode not being able to distinguish between different pointer types.

The type byte*[] isn't a pointer type, it's actually an array type.
And that code can compiled by older csc.exe compilers.
So I think maybe that's a bug, not feature.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

binki picture binki  路  3Comments

marler8997 picture marler8997  路  3Comments

joshua-mng picture joshua-mng  路  3Comments

NikChao picture NikChao  路  3Comments

asvishnyakov picture asvishnyakov  路  3Comments