Pure null check in binary operator doesn't affect 'else' branch
See original GitHub issueVersion Used: e7bad77
Steps to Reproduce: SharpLab link
#nullable enable
public class C {
public void M(string a, string b) {
if (a is null && b is null)
{
}
else
{
a.ToString(); // warning
b.ToString(); // should warn, but doesn't
}
a.ToString(); // warning
b.ToString(); // warning
}
}
I don’t know why ‘a’ is considered maybe-null in the else branch here but not ‘b’. One key detail to note is that the declared types are non-nullable.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
c# - Does the "?." operator do anything else apart from ...
The ?. operator is just implemented in a way that it replaces the very same idioms that work for reference types also for...
Read more >Should one check for null if he does not expect null?
I get really frustrated when people check if the value is null and then try to write some code that doesn't make any...
Read more >Expressions and operators - JavaScript - MDN Web Docs
This chapter describes JavaScript's expressions and operators, including assignment, comparison, arithmetic, bitwise, logical, string, ternary ...
Read more >Warning Options (Using the GNU Compiler Collection (GCC))
Do warn about implicit conversions from arithmetic operations even when conversion of the operands to the same type cannot change their values. This...
Read more >Nim Manual
Strings in Nim may contain any 8-bit value, even embedded zeros. However, some operations may interpret the first binary zero as a terminator....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Check
NullableWalker.LearnFromNullTest
(I think) andNullableWalker.VisitBinaryOperatorChildren
. I would debug and add a watch forthis
, step through, and see how it is that we make it into theelse
block in a state whereb
is not-null.Weird, maybe there’s actually a different code path for
&&
. Given that I would break onReportPossibleNullReceiverIfNeeded
and check the call stack, or if even that fails break onDiagnosticBag.Add
😉