Skip to content

Switch not Handling Goto Case XXX #316

@jcdickinson

Description

@jcdickinson

The switch/case logic is not handling goto case ...; instead either complicated ifs are generated or a bunch of labels and gotos are generated after the switch.

Set of ifs:

string test = "hello";

switch (test)
{
    case "hello":
        Console.WriteLine("Foo");
        goto case "bar";
    case "bar":
        Console.WriteLine("Bar");
        break;
    case "baz":
        Console.WriteLine("Bar");
        break;
    case "frob":
        Console.WriteLine("Bar");
        goto case "bar";
}

We get (which is likely 'correct'):

string test = "hello";
string text = test;
if (text != null)
{
    if (!(text == "hello"))
    {
        if (!(text == "bar"))
        {
            if (text == "baz")
            {
                Console.WriteLine("Bar");
                return;
            }
            if (!(text == "frob"))
            {
                return;
            }
            Console.WriteLine("Bar");
        }
    }
    else
    {
        Console.WriteLine("Foo");
    }
    Console.WriteLine("Bar");
}

For the goto example decompile System.Web.Mvc.Html.InputExtensions::InputHelper from System.Web.Mvc (Version 3.0.0.0).

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions