Bug 660569

Summary: code analysis error when using a switch within a lamda: "Not all code paths return a value in anonymous method"
Product: [Mono] Mono: Compilers Reporter: David Schmitt <david>
Component: C#Assignee: Marek Safar <msafar>
Status: RESOLVED DUPLICATE QA Contact: Mono Bugs <mono-bugs>
Severity: Normal    
Priority: P5 - None    
Version: 2.8.x   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description David Schmitt 2010-12-20 16:55:19 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
Comment 1 Marek Safar 2010-12-20 19:28:56 UTC
duplicate

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