Report errors for union members that are not permitted#82626
Conversation
|
|
||
| union S7(int, bool) | ||
| { | ||
| public S7() |
There was a problem hiding this comment.
Consider testing default parameters, both as a single arg and as a second arg.
There was a problem hiding this comment.
Consider testing default parameters, both as a single arg and as a second arg.
I do not find this scenario interesting because default parameters do not change amount of parameters.
|
@RikkiGibson, @jjonescz, @dotnet/roslyn-compiler For a second review |
| Diagnostic(ErrorCode.ERR_UnionConstructorCallsDefaultConstructor, "S10").WithLocation(36, 5), | ||
| // (53,7): error CS9406: A constructor declared in a 'union' declaration must have a 'this' initializer that calls a synthesized constructor or an explicitly declared constructor. | ||
| // : this() | ||
| Diagnostic(ErrorCode.ERR_UnionConstructorCallsDefaultConstructor, "this").WithLocation(53, 7) |
There was a problem hiding this comment.
Do we have a test for a union declaration with a constructor with a this initializer that calls an explicitly declared constructor? #Resolved
There was a problem hiding this comment.
Do we have a test for a union declaration with a constructor with a this initializer that calls an explicitly declared constructor?
The first constructor in S9
union S9(int, bool)
{
S9(int x, bool y)
: this()
{}
#line 30
public S9()
{}
}
There was a problem hiding this comment.
Right, I guess I would also like to see a test where that called constructor has some parameters.
* upstream/main: (56 commits) [main] Source code updates from dotnet/dotnet (dotnet#82655) Update insert.yml to use roslyn-tools for insertions (dotnet#82615) Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2921538 Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2921538 Reduce allocations during source text diffing (dotnet#82462) Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2920904 Localized file check-in by OneLocBuild Task: Build definition ID 327: Build ID 2920904 Revert "Throw NotImplementedException when a build errorId is not supported" (dotnet#82638) [main] Source code updates from dotnet/dotnet (dotnet#82623) Revert System.ValueTuple version update (dotnet#82639) Pack enum values Track non-blocking PROTOTYPE comments for `Unions` feature in an issue (dotnet#82637) Update the build system errors instructions for Visual Studio 2026 Don't log named pipe connection failures as errors in BuildServerConnection (dotnet#82609) Fix resx source generator for less common resx metadata and locations (dotnet#81994) Disallow `ref` modifier for a union declaration (dotnet#82632) Add IFSharpInlineHintsService2 for displayAllOverride support (dotnet#82629) Report errors for union members that are not permitted (dotnet#82626) Check language version for union matching and conversions (dotnet#82617) [main] Update dependencies from dotnet/arcade (dotnet#82618) ...
| S1(string x) | ||
| : this(1) {} |
There was a problem hiding this comment.
This constructor is private, is it really expected to be reported? Message says only about "public constructors" 🤔
There was a problem hiding this comment.
This constructor is private, is it really expected to be reported? Message says only about "public constructors" 🤔
Good catch. Looks like an oversight.
No description provided.