Bug 6587 - mcs does not properly handle variables when compiling IEnumerable<T> method
Summary: mcs does not properly handle variables when compiling IEnumerable<T> method
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2012-08-17 16:43 UTC by Martin Potter
Modified: 2012-09-03 04:22 UTC (History)
1 user (show)

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


Attachments
Sample program that reproduces the bug (415 bytes, application/octet-stream)
2012-08-17 16:43 UTC, Martin Potter
Details


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:
Status:
RESOLVED FIXED

Description Martin Potter 2012-08-17 16:43:53 UTC
Created attachment 2371 [details]
Sample program that reproduces the bug

The attached program compiles fine with mcs, but does not handle the variable correctly; when run, it results in a NullReferenceException. Looking at the compiled code, the variable is defined as local to the MoveNext method, so assigned value does not persist to the next call to MoveNext. When compiled with gmcs, the program runs as expected.

Steps to reproduce:

1. Compile the attached program with mcs
2. Run the program


Expected Results:

Executing action
Action executed

Is output to the console.


Actual Results:

Executing action

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
  at CompilerBug.CompilerBug+<Foo>c__Iterator0.MoveNext () [0x00000] in <filename unknown>:0 
  at CompilerBug.CompilerBug.Main (System.String[] arguments) [0x00000] in <filename unknown>:0
Comment 1 Martin Potter 2012-08-24 20:15:57 UTC
This appears to be a result of this commit: https://github.com/mono/mono/commit/394140f5a495ff5fc718249c1406735a001edf85.
Comment 2 Martin Potter 2012-08-26 15:37:57 UTC
Submitted pull request with fix, https://github.com/mono/mono/pull/445.
Comment 3 Marek Safar 2012-09-02 12:49:51 UTC
Fixed in master
Comment 4 Martin Potter 2012-09-02 14:52:41 UTC
The same change should also be made to the if statement for await that follows, as it suffers from the same issue.
Comment 5 Marek Safar 2012-09-03 04:22:49 UTC
Indeed.

Fixed in master too now.