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 produces CS8862: A constructor declared in a record with parameter list must have 'this' constructor initializer, which is expected. To fix this error, add a call to the default constructor:
Expected Behavior:
The struct is created and printed with First and Second set to default(char).
Actual Behavior:
A System.InvalidProgramException is thrown during execution:
Unhandled exception. System.InvalidProgramException: Common Language Runtime detected an invalid program.
at S..ctor(Object o)
at Program.<Main>$(String[] args) in D:\<path_ommited>\Program.cs:line 1
Full code:
Occurs both when running compiled to Debug and Release.
HOWEVER then the parameter is initalized to garbage -- in my case it's the char '?', but it's clearly not zero-initialized. Changing the type to int produces a seemingly random value, probably a piece of memory that wasn't initialized.
I believe the compiler should require that explicit constructors in the record struct call either the implicit primary constructor or another explicit constructor.
The constructors above that call this() should be reported as errors since the primary constructor and explicit constructors have parameters in each case.
Version Used:
.NET SDK:
Version: 6.0.100
Commit: 9e8b04bbff
Steps to Reproduce:
Expected Behavior:
The struct is created and printed with
First
andSecond
set todefault(char)
.Actual Behavior:
A
System.InvalidProgramException
is thrown during execution:Full code:
Occurs both when running compiled to Debug and Release.
https://dotnetfiddle.net/85o0Th
The text was updated successfully, but these errors were encountered: