Bug 20686 - The out parameter must be set before control leaves the current context when assigning value in conditional expression
Summary: The out parameter must be set before control leaves the current context when ...
Status: RESOLVED DUPLICATE of bug 20515
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2014-06-18 14:07 UTC by Kevin Skrei
Modified: 2014-06-19 11:56 UTC (History)
1 user (show)

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

Bug in sample (12.31 KB, application/zip)
2014-06-18 14:07 UTC, Kevin Skrei

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 Kevin Skrei 2014-06-18 14:07:24 UTC
Created attachment 7106 [details]
Bug in sample

When assigning an out parameter in conditional statement with the ternary operator, the method won't compile. This is a regression since the sample project compiles fine on the stable channel but won't compile on the alpha channel. I noticed the Mono version in stable is 3.4 and in alpha is 3.6 

Here is an example

private bool TestSucceed(uint b, out uint a)
        //Works fine
	int c = 0;
	if ((a = Set (b, c)) != 0)
	    return true;

	    return false;

private bool TestFail(uint b, out uint a)
	int c = 0;
	//Taking the conditional '(c == 0 ? 0 : 0)' and replacing it with a valid int will make this compile
	if ((a = Set (b, c == 0 ? 0 : 0)) != 0)
		return true;

	return false;

private uint Set(uint test, int x)
	return 0;

Attached is a sample project with this error. Let me know if any further information is needed.
Comment 1 Marek Safar 2014-06-19 11:56:24 UTC

*** This bug has been marked as a duplicate of bug 20515 ***