Bug 17519 - Incorrect error CS0165 "Use of unassigned local variable" for identically named type and local variable
Summary: Incorrect error CS0165 "Use of unassigned local variable" for identically nam...
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: 3.2.x
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2014-01-30 14:45 UTC by Richard Cook
Modified: 2014-02-25 13:17 UTC (History)
4 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 Richard Cook 2014-01-30 14:45:45 UTC
When a method defines a local variable named identically to a class and attempts to invoke a static method on the class, mcs incorrectly reports error CS0165 "Use of unassigned local variable". Here's a simple repro case:

===== Test.cs =====

public class A
    public static A Get() { return null; }

public class Test
    void M()
        A A = A.Get();

===== End of Test.cs =====

===== Sample command lines =====

# From Visual Studio 2013 command prompt:
$ csc /target:library Test.cs
Microsoft (R) Visual C# Compiler version 12.0.21005.1
Copyright (C) Microsoft Corporation. All rights reserved.

[No errors]

# From Mono 2.10.9 command prompt:
$ mcs /target:library Test.cs

[No errors]

# From Mono 3.2.3 command prompt:
$ mcs /target:library Test.cs
Class1.cs(10,15): error CS0165: Use of unassigned local variable `A'
Compilation failed: 1 error(s), 0 warnings

===== End of sample command lines =====

Thus, this source file is compiled by csc and mcs version 2.10.9. mcs 3.x fails to compile this code. This looks like a regression between the 2.x and 3.x series of the mcs compiler.

Thanks, Richard.

Richard Cook | Principal engineer
Coverity | Columbia Center Tower | 701 Fifth Avenue, Suite 1220 | Seattle, WA
The Leader in Development Testing
Read our profile in Forbes, Coverity Gets Code Right 25% Faster
Comment 1 Marek Safar 2014-01-30 14:53:24 UTC
Already fixed in master and Mono 3.2.7
Comment 2 Richard Cook 2014-01-30 14:57:50 UTC
Could you provide the commit hash for the fix?
Comment 3 Marek Safar 2014-01-30 15:00:27 UTC
I don't think there was single commit. It was probably fixes as part of flow-analysis rewrite which is ~10 commits