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# (show other bugs)
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-06-18 14:07 UTC by Kevin Skrei
Modified: 2014-06-19 11:56 UTC (History)
1 user (show)

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


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

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 ***

Note You need to log in before you can comment on or make changes to this bug.