[Mono-bugs] [Bug 493887] New: Switch selects wrong branch when default is not last case

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Apr 10 07:16:28 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=493887


           Summary: Switch selects wrong branch when default is not last
                    case
    Classification: Mono
           Product: Mono: Compilers
           Version: 2.4.x
          Platform: x86
        OS/Version: All
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: alexander.shulgin at yessoftware.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Community User


The C# switch statement selects wrong case block when the `default:' statement
is used in uncommon position.

Sample code:

using System;

namespace default_case_bug
{
  class Program
  {
    static void Main(string[] args)
    {
      string val = "A";
      int res = 0;
      switch (val)
      {
        case "A":
        default:
          res = 1;
          break;

        case "B":
          res = 2;
          break;
      }
      Console.WriteLine("result: {0}", res);
    }
}

This code gives

result: 2

While it should give

result: 1

This happens with various versions of mono (2.4, SVN trunk) on different
platforms (Mac, Windows, Linux) all running on Intel 32-bit processors.

The problem doesn't happen with numeric types (int).

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list