Giter Site home page Giter Site logo

Comments (4)

jjonescz avatar jjonescz commented on August 17, 2024
Dictionary<string, List<bool>> d = new();
bool e = d.TryGetValue("hi", out List<bool>? list);
if (!e)
{
    list = new();
}
Console.WriteLine(list.Count);

Nullability info isn't propagated through boolean variables like that. See #27011.

If you "inline" the check, it works:

Dictionary<string, List<bool>> d = new();
if (!d.TryGetValue("hi", out List<bool>? list))
{
    list = new();
}
Console.WriteLine(list.Count);

from roslyn.

AArnott avatar AArnott commented on August 17, 2024

Thanks for looking.
In the case I got this from, I need the bool local because it is used in later expressions. So it isn't as simple as inlining it, which is what I normally do.

from roslyn.

jjonescz avatar jjonescz commented on August 17, 2024

I agree it would be useful to support this, but I think it needs a language proposal - #27011 (comment).

from roslyn.

jaredpar avatar jaredpar commented on August 17, 2024

The current behavior is indeed "By Design". I agree it's unfortunate and it would be nice if this worked. Getting this to work though is not a trivial undertaking, it's a significant amount of design and implementation work. Rikki wrote up a summary of the problems that this poses.

from roslyn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.