Skip to content
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

Lack of CS0165 (Use of unassigned local variable) for DateOnly and TimeOnly types #77177

Closed
Wojmik opened this issue Oct 18, 2022 · 7 comments
Closed

Comments

@Wojmik
Copy link

Wojmik commented Oct 18, 2022

Version Used:
.Net 6. Visual Studio 17.3.6.

Steps to Reproduce:

DateOnly date;
TimeOnly time;

Console.WriteLine(date);//Lack of CS0165 - unassigned local variable
Console.WriteLine(time);//Same here

Expected Behavior:
You should have CS0165 error (Use of unassigned local variable).
If you change a type to e.g. DateTime, the error appears like it should.

Actual Behavior:
No error, you can compile and run it.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Oct 18, 2022
@RikkiGibson
Copy link
Contributor

I'm seeing that the ref assembly containing DateOnly does not contain any fields. Therefore the compiler considers it to be "vacuously" assigned--after all, all zero of the fields in it are assigned.

Rerouting issue to runtime repo.

image

@RikkiGibson RikkiGibson transferred this issue from dotnet/roslyn Oct 18, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented Oct 18, 2022

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

Issue Details

Version Used:
.Net 6. Visual Studio 17.3.6.

Steps to Reproduce:

DateOnly date;
TimeOnly time;

Console.WriteLine(date);//Lack of CS0165 - unassigned local variable
Console.WriteLine(time);//Same here

Expected Behavior:
You should have CS0165 error (Use of unassigned local variable).
If you change a type to e.g. DateTime, the error appears like it should.

Actual Behavior:
No error, you can compile and run it.

Author: Wojmik
Assignees: -
Labels:

area-Infrastructure-libraries, untriaged

Milestone: -

@ghost
Copy link

ghost commented Oct 19, 2022

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

Version Used:
.Net 6. Visual Studio 17.3.6.

Steps to Reproduce:

DateOnly date;
TimeOnly time;

Console.WriteLine(date);//Lack of CS0165 - unassigned local variable
Console.WriteLine(time);//Same here

Expected Behavior:
You should have CS0165 error (Use of unassigned local variable).
If you change a type to e.g. DateTime, the error appears like it should.

Actual Behavior:
No error, you can compile and run it.

Author: Wojmik
Assignees: -
Labels:

area-System.Runtime, untriaged

Milestone: -

@ViktorHofer
Copy link
Member

Changing label to System.Runtime as this is about System.Runtime's reference assembly.

@dakersnar
Copy link
Contributor

cc @tarekgh as this is DateTime related

@tarekgh
Copy link
Member

tarekgh commented Oct 19, 2022

This is fixed in .NET 7.0. Please try it and let's know if you still see the problem there. Thanks for your report.

@tarekgh tarekgh closed this as completed Oct 19, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Oct 19, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants