-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C#: C#9 Add target typed conditional tests #4614
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
C#: C#9 Add target typed conditional tests #4614
Conversation
98cc972
to
3ef211b
Compare
@@ -0,0 +1,2 @@ | |||
| TargetType.cs:12:18:14:18 | ... ? ... : ... | int? | int? | null | |
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 means that the extractor does not insert implicit casts in the branches, I think it should. What do you think?
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 we need the implicit casts, because that's not what happens in IL:
int? x = condition ? 5 : null;
becomes the following in IL:
Nullable<int> num = condition ? new Nullable<int>(5) : new Nullable<int>();
So there's no implicit cast. The problem is more like that we're not extracting nullables in the most accurate way. This could probably become part of https://github.com/github/codeql-csharp-team/issues/82.
Does it cause any issue in QL if the two branches of the conditional have different types? If so, then the short term fix is probably what you suggest, to add the implicit cast.
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.
OK; nullables are special (I forgot). But how about the other test case below?
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 no conv.
or castclass
in IL for the latter case either, so why would we add a cast?
On the other hand, I think we add an implicit cast for the extraction of IEnumerable<int> xs = new int[]{};
. And if we really do, then I think we should/must also add the cast for ?:
too.
What is the motivation behind having the implicit cast in the first place?
What do you think?
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 am not convinced that the implicit casts are in fact that important. However, in cases where the implicit cast is via an operator, we should add it (both in assignments and in ternary conditionals).
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.
@hvitved I pushed an extra commit with some additional tests. Implicit casts and conversion calls do show up in the output.
cf82628
to
548f276
Compare
No description provided.