Bug 1879 - Compiler does not catch use of uninitialized variable
Summary: Compiler does not catch use of uninitialized variable
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2011-11-04 10:40 UTC by Matt
Modified: 2013-11-29 03:40 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Matt 2011-11-04 10:40:19 UTC
This code can result in an access of the List list, without it being initialized (in the case b is false):

        public static void Foo(bool b)
            int i;
            List<int> list;
            if (b && !dict.TryGetValue("foo", out list)) {
                dict["foo"] = new List<int>();
            } else {
                i = list[0];

Visual studio flags this as a compiler error. I am using:

$ mono --version
Mono JIT compiler version 2.11 ((no/7917753 Wed Mar 30 15:47:09 EDT 2011)
Copyright (C) 2002-2011 Novell, Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug
    LLVM:          yes(2.8svn-mono)
    GC:            Included Boehm (with typed GC and Parallel Mark)
Comment 1 Ben Bader 2013-07-23 14:58:52 UTC
Any update on this bug?  It's 2.5 years later, and we're still getting bitten by this from time to time...
Comment 2 Marek Safar 2013-11-29 03:40:29 UTC
Fixed in master