Bug 23475 - "Invalid IL code ... method body is empty" when using fallthrough case in switch statement
Summary: "Invalid IL code ... method body is empty" when using fallthrough case in swi...
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-09-29 22:34 UTC by Brendan Zagaeski (Xamarin Support)
Modified: 2014-09-30 05:18 UTC (History)
1 user (show)

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


Attachments

Description Brendan Zagaeski (Xamarin Support) 2014-09-29 22:34:27 UTC
"Invalid IL code ... method body is empty" when using fallthrough case in switch statement.

This is a sibling of the earlier bug 21805. I'm not sure if this situation is specifically mentioned in the C# specification, so the current behavior might not necessarily be "wrong."


## Steps to reproduce

1. Compile the following program using `mcs`:

using System;

public enum Foo { One, Two };

class MainClass
{
    public static void Main(string[] args)
    {
        const Foo foo = Foo.Two;
        object obj;

        switch (foo)
        {
            case Foo.One:
            case Foo.Two:
                obj = new object();
                break;
        }
        Console.WriteLine(obj.ToString());
    }
}


2. Run the program with `mono`.


## Result when compiled with `mcs`

### Command-line output from step 2

> $ mono Program.exe
> Unhandled Exception:
> System.InvalidProgramException: Invalid IL code in MainClass:Main (string[]): method body is empty.
> 
> [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidProgramException: Invalid IL code in MainClass:Main (string[]): method body is empty.


## Result when compiled with `csc`

> $ mono Program.exe
> System.Object



## Additional result (same on both `mcs` and `csc`)

If you remove `const` from the `foo` local variable, both compilers reject the code due to "Use of unassigned local variable 'obj'". Since `csc` has the same behavior as `mcs` in this "additional" case, the only issue with `mcs` is when `foo` is *not* marked `const`.



## Version Information

Tested with Mono 3.10.0 (detached/ac51002) and 3.10.1 (master/4e3ca74).
Comment 1 Marek Safar 2014-09-30 05:18:08 UTC
Fixed in master

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