You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is currently allowed in the language without error:
using X =List<int*[]>;
This is due to the compiler only checking directly that the type parameters of a generic type are managed types, and 'Arrays' are managed types.
However, this should likely be illegal as the spec defines the concept of an Unsafe Context, which is the only location where pointers can even be syntactically used.
We need to decide what to do about this. Given that the above code was allowed since C#2.0 there is a def compat concern if we were to disallow this.
That said, in C# 12 we added the ability to say using unsafe X = .... This gives us the option to say that in C# 12 we would now make this required, but continue to allow it in C#11 and prior. We could potentially also have our upgrade-fixers detect/fix this in the rare, but possible, chance that this comes up in the wild.
The text was updated successfully, but these errors were encountered:
CyrusNajmabadi
changed the title
Compiler allows pointer to be used in using-alias
Compiler erroneously allows pointer to be used within a type-argument in a using-alias
Mar 13, 2023
This is currently allowed in the language without error:
This is due to the compiler only checking directly that the type parameters of a generic type are
managed types
, and 'Arrays' are managed types.However, this should likely be illegal as the spec defines the concept of an Unsafe Context, which is the only location where pointers can even be syntactically used.
We need to decide what to do about this. Given that the above code was allowed since C#2.0 there is a def compat concern if we were to disallow this.
That said, in C# 12 we added the ability to say
using unsafe X = ...
. This gives us the option to say that in C# 12 we would now make this required, but continue to allow it in C#11 and prior. We could potentially also have our upgrade-fixers detect/fix this in the rare, but possible, chance that this comes up in the wild.The text was updated successfully, but these errors were encountered: