-
Notifications
You must be signed in to change notification settings - Fork 4.2k
var should infer nullable type #40755
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
Conversation
f58c3b0 to
7e0227e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😟 Did this just go from O(1) to O(n)? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔ Was this just a test or was it needed for some reason? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explained in OP: Filed issue #40821 to track the remaining issue with analysis of local functions which affected bootstrapping for this PR.
The code above behaves like Solution? solution = ...; which hits a problem with analysis of local functions. Most such problems were fixed by Andy yesterday, but one or two remained, which I worked around to unblock this PR (because it's not a new problem).
In reply to: 364502291 [](ancestors = 364502291)
|
Could you please prepare a corresponding PR to adjust a specification in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToAnnotatedTypeWithAnnotations [](start = 76, length = 30)
We should consider not changing this one. The foreach variable is readonly, so nobody's going to be assigning null to it. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed in more details in another thread in this PR. Tagged you there. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only be done for variables declared with a var pattern. The others should stay non-null. #Resolved
|
Finished reviewing (Iteration 4). I did not review tests deeply because I fear fixing the treatment of pattern variables may change the tests a lot. #Resolved |
jasonmalinowski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still trying to sort out the IDE changes. (Making progress though!)
|
@jasonmalinowski the PR no longer has logic change in the IDE (only tests and two explicit types for bootstrap issue) #Resolved |
jasonmalinowski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comprehensive IDE testing on UseExplicitType. There was one test that looked like it was asserting the wrong thing, and one also that was asserting the wrong thing which you did know about but there's a difference of how the compiler and IDE teams handle tests like that. Comments in that file.
We also should have some tests probably too on UseImplicitType to make sure we're not converting things to var if they're non-nullable, but I'm happy to file a tracking item to do that separately since I suspect any bugs you find there are existing bugs and not new bugs with this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like you're now testing #37309, so you may want to close that too. #WontFix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's probably other code/tests tagged with this issue. I'll leave that separate for now.
In reply to: 367219324 [](ancestors = 367219324)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also test typeInfo.Type.NullableAnnotation and typeInfo.ConvertedType.NullableAnnotation, or is that automatic at this point? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the throw null! matter here for some reason? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the throw null! matters, but code that doesn't compile makes me uncomfortable ;-) #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be (Program? y1)? Or otherwise this is assigning a nullable x to a non-nullable y1? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm not going to block this PR on this concern since this is an edge case, but I am curious!) #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is capturing existing behavior. I'll update to capture desired behavior instead, as you indicated.
In reply to: 367220385 [](ancestors = 367220385)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IDE has a different pattern than the compiler here: make the test assert what should happen and then skip the test by putting the bug number in the skip attribute. We avoid having tests assert the wrong thing because it often means somebody who accidentally fixes the bug might think they made things worse, and not realize they actually made things better. The counter-argument of "but you want to know about further changes" we don't usually worry about. #Resolved
|
Moved this PR to 16.6p1 branch because of concerns with possible implications to other test scenarios. #Resolved |
|
Rebased on top of dev16.6-preview1 and will merge when green. |
Fixes #40477 based on recent LDM decision.
Fixes #31874
Blocked on #40422 (which fixes a bug with analysis of local functions which prevents bootstrapping)Filed issue #40821 to track the remaining issue with analysis of local functions which affected bootstrapping for this PR.