Bugzilla – Bug 660569
code analysis error when using a switch within a lamda: "Not all code paths return a value in anonymous method"
Last modified: 2010-12-20 19:28:56 UTC
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10 ccnet@squeeze:~/tmp$ cat switch-return.cs using System; using System.Collections.Generic; using System.Linq; using System.Reflection; public class Test { public static IEnumerable<int> Error(IEnumerable<BindingFlags> f) { return f.Select(p => { switch(p) { case BindingFlags.Default: return 1; default: return 2; }; }); } public static int Works(BindingFlags f) { switch(f) { case BindingFlags.Default: return 1; default: return 2; } } } ccnet@squeeze:~/tmp$ gmcs /t:library switch-return.cs switch-return.cs(8,33): error CS1643: Not all code paths return a value in anonymous method of type `System.Func<TSource,TResult>' Compilation failed: 1 error(s), 0 warnings Reproducible: Always Steps to Reproduce: 1. Compile the example code Actual Results: switch-return.cs(8,33): error CS1643: Not all code paths return a value in anonymous method of type `System.Func<TSource,TResult>' Compilation failed: 1 error(s), 0 warnings Expected Results: should compile without error This works in CSC 2010, but neither with gmcs 2.8.1 nor 2.6.7.0
duplicate *** This bug has been marked as a duplicate of bug 336258 ***