-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No error for unassigned out parameter, bug? #2674
Comments
With a non-empty custom struct, I do get an error, which makes sense, I guess. But it doesn't explain the behavior with |
An empty struct won't error because a struct is considered assigned if all it's fields are assigned, and so an empty struct is always assigned. |
Yes, but |
Are you working with a reference assembly? IIRC there was an issue that because reference structs lacked fields that the compiler could treat them as empty. I forget what the resolution was to resolve that. |
I think so, yes. I'm using the latest VS2019 Preview and the latest .NET Core 3 SDK.
I also seem to remember something like that. |
But this issue is supposed be fixed... |
If the fix for the issue was recreating the reference assemblies with the dummy field maybe that wasn't done for ASP.NET? |
Well, the reference definition of And I checked on my machine, the reference assemby for Microsoft.AspNetCore.Http.Abstractions also contains the dummy field. So the problem must be somewhere else... |
Is this a language bug then, or a compiler bug? |
Compiler, I think |
This probably wants to be in dotnet/roslyn, then, rather than dotnet/csharplang |
Maybe... I don't have the rights to transfer the issue, though. |
As far as I can tell, this has the same source as dotnet/roslyn#29319: Roslyn intentionally ignores private reference type fields in referenced assemblies for purposes of definite assignment, to maintain compatibility. Though it seems https://github.com/dotnet/roslyn/issues/33288 (of which this issue is a duplicate) indicates this might change in the future. |
As this is a duplicate of a roslyn bug, I'm going to close this bug. If we want to make a language change, we can open one later. |
Works for me. In the meantime I'll use the |
Just fixed a bug that was caused by an unassigned out parameter. Normally the compiler emits an error for this, but in this case it doesn't.
This code produces an error, as expected:
Same result when the parameter is
int
orDateTime
.But this one doesn't produce any error:
(
PathString
is areadonly struct
fromMicrosoft.AspNetCore.Http
)I also don't get an error if the parameter is a custom struct (e.g.
struct Foo {}
), whether it's readonly or not.I'm not sure what's going on here. Why does it produce an error for some types, but not for others?
I get this behavior in C# 7 and 8, didn't check earlier versions.
Is there a logical explanation, or is it a bug in the compiler?
The text was updated successfully, but these errors were encountered: