[Mono-bugs] [Bug 22198] New - switch cases with string literals fail to match properly
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
20 Mar 2002 06:10:51 -0000
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by mkestner@speakeasy.net.
http://bugzilla.ximian.com/show_bug.cgi?id=22198
--- shadow/22198 Wed Mar 20 01:10:51 2002
+++ shadow/22198.tmp.5597 Wed Mar 20 01:10:51 2002
@@ -0,0 +1,61 @@
+Bug#: 22198
+Product: Mono/Runtime
+Version: unspecified
+OS: other
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: mkestner@speakeasy.net
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: switch cases with string literals fail to match properly
+
+mono and mcs from cvs 19:00 CST 3/19
+
+behavior is correct on win32 with mcs compiled binary
+behavior is incorrect on both mono and mint
+
+comparison of composed strings to case "literals": fails. The behavior
+seems to indicate that the runtime matching that is applied for the switch
+cases requires address equivalence, not string equivalence. A literal
+assigned to a string variable matches properly. However, when a string is
+composed from a char[], the resulting string does not match against an
+equivalent string literal.
+
+The following test code demonstrates the problem:
+
+namespace StringCaseTest {
+
+ using System;
+
+ public class TestClass {
+
+ public static void Main ()
+ {
+ char[] tchars = {'t', 'e', 's', 't'};
+ string tstr = new String(tchars);
+ Console.WriteLine(tstr);
+
+ if (tstr == "test")
+ Console.WriteLine("Direct comparison works");
+ else
+ Console.WriteLine("Direct comparison fails");
+
+ switch (tstr) {
+
+ case "test":
+ Console.WriteLine("Should go here");
+ break;
+ default:
+ Console.WriteLine("But it hits the default");
+ break;
+ }
+ }
+ }
+}