records, with expression, required property
I'm hitting a strange behaviour and not sure if it's intended.
I have the following record definition:
Then I use it in code like this:
Why is
config2.DataSource
null? Is this intended behaviour of combining required
and with
?
If so, shouldn't I get a warning/error that I have an uninitialised required property in config2
?12 Replies
Can't repro?
canton7
REPL Result: Success
Console Output
Compile: 514.274ms | Execution: 108.868ms | React with ❌ to remove this embed.
Can you please just share code directly, rather than asking us to download zip files? You can use $paste if it's longer
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
Because I'm not downloading a zip file from a random discord user, sorry
https://github.com/seky16/record-tc/blob/master/WebAPI/Handler.cs
Not sure if it's inheritance or the
IsExternalInit
hack that's causing the trouble333fred
REPL Result: Success
Console Output
Compile: 585.355ms | Execution: 99.468ms | React with ❌ to remove this embed.
Alright, so this is something with your multi-targeting
If I switch your Expressions project to net8.0, it works fine
@seky16 looks like we have an existing bug on this, https://github.com/dotnet/roslyn/issues/72357. Can you add a comment to ping the issue again?
GitHub
Issues · dotnet/roslyn
The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs. - Issues · dotnet/roslyn
Good news @seky16, you nerd sniped me into fixing this: https://github.com/dotnet/roslyn/pull/76347
GitHub
Do not bail generating base type initializer in the presence of use...
We were returning early from generating a call to the base record copy constructor initializer if use site diagnostics reported any kind of diagnostic, including warnings. This isn't good i...
thanks! yeah workaround with targeting
net8.0
works, so that's great