From: Marek Safar Date: Mon, 25 Nov 2013 14:56:46 +0000 (+0100) Subject: [mcs] Arguments flow analysis needs to ignore out modifier. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=1d5cefe7ad5e5253a410ec3dd5c6e825317c7557;p=mono.git [mcs] Arguments flow analysis needs to ignore out modifier. --- diff --git a/mcs/errors/cs0165-29.cs b/mcs/errors/cs0165-29.cs new file mode 100644 index 00000000000..238093d4575 --- /dev/null +++ b/mcs/errors/cs0165-29.cs @@ -0,0 +1,12 @@ +// CS0165: Use of unassigned local variable `j' +// Line: 10 + +class Test +{ + static void Main () + { + int? i; + int? j; + int? x = (i = 7) ?? j; + } +} \ No newline at end of file diff --git a/mcs/errors/cs0165-30.cs b/mcs/errors/cs0165-30.cs new file mode 100644 index 00000000000..c800affb130 --- /dev/null +++ b/mcs/errors/cs0165-30.cs @@ -0,0 +1,11 @@ +// CS0165: Use of unassigned local variable `a' +// Line: 9 + +using System; + +class Test { + + static void Main () { + Action a = () => a(); + } +} \ No newline at end of file diff --git a/mcs/errors/cs0165-31.cs b/mcs/errors/cs0165-31.cs new file mode 100644 index 00000000000..07759cbe0f1 --- /dev/null +++ b/mcs/errors/cs0165-31.cs @@ -0,0 +1,11 @@ +// CS0165: Use of unassigned local variable `i' +// Line: 9 + +public class MainClass +{ + public void Foo () + { + int i; + i++; + } +} diff --git a/mcs/errors/cs0165-32.cs b/mcs/errors/cs0165-32.cs new file mode 100644 index 00000000000..fb9652267c8 --- /dev/null +++ b/mcs/errors/cs0165-32.cs @@ -0,0 +1,16 @@ +// CS0165: Use of unassigned local variable `a' +// Line: 9 + +class C +{ + static void Main () + { + int a; + Foo (out a, a); + } + + static void Foo (out int a, int b) + { + a = b; + } +} \ No newline at end of file diff --git a/mcs/mcs/argument.cs b/mcs/mcs/argument.cs index c516ffde5b0..13d0526cc2c 100644 --- a/mcs/mcs/argument.cs +++ b/mcs/mcs/argument.cs @@ -499,8 +499,25 @@ namespace Mono.CSharp public void FlowAnalysis (FlowAnalysisContext fc) { - foreach (var arg in args) + bool has_out = false; + foreach (var arg in args) { + if (arg.ArgType == Argument.AType.Out) { + has_out = true; + continue; + } + arg.FlowAnalysis (fc); + } + + if (!has_out) + return; + + foreach (var arg in args) { + if (arg.ArgType != Argument.AType.Out) + continue; + + arg.FlowAnalysis (fc); + } } public List.Enumerator GetEnumerator ()