-
Notifications
You must be signed in to change notification settings - Fork 231
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
SE - Nullable: Add Null
constraint for empty nullable constructor
#6853
Conversation
@@ -67,10 +67,15 @@ public static IEnumerable<SymbolicContext> Process(SymbolicContext context) | |||
{ | |||
if (Simple.TryGetValue(context.Operation.Instance.Kind, out var simple)) // Operations that return single state | |||
{ | |||
context = context.WithState(simple.Process(context)); | |||
return new[] { context.WithState(simple.Process(context)) }; |
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.
Unrelated improvement. If an operation is registered in the 1st list, there's no reason look in the 2nd one too
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.
Do we have some kind of test or check, so that we don't end up with one operation kind in both lists?
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.
No, we don't. It should be easy to catch, as the change goes for "simple" first, so whatever complex logic we'll have should just not work. And should be easy to catch
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.
LGTM. I have one question regarding the optimization, though.
@@ -67,10 +67,15 @@ public static IEnumerable<SymbolicContext> Process(SymbolicContext context) | |||
{ | |||
if (Simple.TryGetValue(context.Operation.Instance.Kind, out var simple)) // Operations that return single state | |||
{ | |||
context = context.WithState(simple.Process(context)); | |||
return new[] { context.WithState(simple.Process(context)) }; |
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.
Do we have some kind of test or check, so that we don't end up with one operation kind in both lists?
{ | ||
const string code = """ | ||
int? explicitType = new Nullable<int>(); | ||
int? targetTyped = new(); |
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.
Propably later:
void M<T>() where T: struct
{
T? a = new T(); // NotNull (this should come from me)
T? b = new T?(); // Null (this should come from you)
}
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 already works - so I've added those cases
"""; | ||
var validator = SETestContext.CreateCS(code).Validator; | ||
validator.ValidateTag("ExplicitType", x => x.HasConstraint(ObjectConstraint.Null).Should().BeTrue()); | ||
validator.ValidateTag("TargetTyped", x => x.HasConstraint(ObjectConstraint.NotNull).Should().BeTrue("new() of int produces value 0")); |
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.
😮 Interesting behavior.
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.
Indeed. It took me a debug session and a manual test to verify. definitely deserves a special message :)
07e9718
to
4e747eb
Compare
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Part of #6812
new Nullable<int>()
should haveNull
constraint