question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pure null check in binary operator doesn't affect 'else' branch

See original GitHub issue

Version 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:open
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
RikkiGibsoncommented, Aug 31, 2020

Check NullableWalker.LearnFromNullTest (I think) and NullableWalker.VisitBinaryOperatorChildren. I would debug and add a watch for this, step through, and see how it is that we make it into the else block in a state where b is not-null.

0reactions
RikkiGibsoncommented, Sep 1, 2020

Weird, maybe there’s actually a different code path for &&. Given that I would break on ReportPossibleNullReceiverIfNeeded and check the call stack, or if even that fails break on DiagnosticBag.Add 😉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found