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
I noticed that we produce a warning if you use StructLayout on a partial (undefined ordering).
Should we do something similar for primary constructors (and record structs)?
Alternatively, we can define/specify/verify the ordering.
// (5,15): warning CS0282: There is no defined ordering between fields in multiple declarations of partial struct 'C'. To specify an ordering, all instance fields must be in the same declaration.
Diagnostic(ErrorCode.WRN_SequentialOnPartialClass, "C").WithArguments("C"));
This was also reported here with an example showing an unexpected execution output.
I agree that all three of these scenarios are related because they have the following properties:
The ordering of members in metadata are not specified by the language / compiler.
The ordering is generally understood because the compiler is deterministic, generally it's the same as lexical order in the files, and we don't change the implementation between releases.
If we were starting from scratch I'd probably push for an error here. Given that partial set the precedence though I think we should just follow on that here and issue a warning. Do think this warning should be tied to lang version 12 though.
AlekseyTs
added a commit
to AlekseyTs/roslyn
that referenced
this issue
Apr 10, 2023
I noticed that we produce a warning if you use StructLayout on a partial (undefined ordering).
Should we do something similar for primary constructors (and record structs)?
Alternatively, we can define/specify/verify the ordering.
This was also reported here with an example showing an unexpected execution output.
Relates to test plan #65697
The text was updated successfully, but these errors were encountered: