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
Instead, an error is only surfaced when attempting to use language syntax with these types:
S2s2=default;S3s3=default;
s2[0]=default;// CS0021: Cannot apply indexing with [] to an expression of type 'S1'
s3[0]=default;// CS0021: Cannot apply indexing with [] to an expression of type 'S1'// For non-constant indexing, the compiler may also surface// CS0306: The type 'int*' may not be used as a type argument
Expected Behavior
Given that S2 and S3 are valid from the runtime perspective and only incompatible with the language support for InlineArray, the compiler should raise a warning that surfaces this incompatibility and that language syntax will not be available.
The developer can then make the decision to suppress the warning or to expose the support in a different manner. For example, the developer could desire still exposing the types "as is" and defining their own helper APIs to allow correct indexing. They could alternatively desire to expose this using some wrapper type or via a same sized alternative.
The following would then all be "valid" options for the user:
// Disable the warning
#pragma warning disable CS----[InlineArray(10)]
public struct S2
{
public int* _x;}
#pragma warning restore CS----// Use a wrapper type
public struct Pointer<T>where T : unmanaged
{
T Value;}[InlineArray(10)]
public struct S2
{
public Pointer<int> _x;}// Use a same sized primitive[InlineArray(10)]
public struct S2
{
public nuint _x;}
Summary
The new
[InlineArray]
works for most, but not all, types. It also currently surfaces errors for some, but not all, "invalid" declarations.For example, the compiler currently surfaces an error if you have more than 1 field:
It does not surface any warning or error for the following code, however:
Instead, an error is only surfaced when attempting to use language syntax with these types:
Expected Behavior
Given that
S2
andS3
are valid from theruntime
perspective and only incompatible with thelanguage
support forInlineArray
, the compiler should raise awarning
that surfaces this incompatibility and that language syntax will not be available.The developer can then make the decision to suppress the warning or to expose the support in a different manner. For example, the developer could desire still exposing the types "as is" and defining their own helper APIs to allow correct indexing. They could alternatively desire to expose this using some wrapper type or via a same sized alternative.
The following would then all be "valid" options for the user:
Relates to test plan #67826
The text was updated successfully, but these errors were encountered: