[Issue 6176] New: [TDPL] Cannot use string variables in case expressions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 19 03:58:17 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6176

           Summary: [TDPL] Cannot use string variables in case expressions
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: jmdavisProg at gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisProg at gmx.com> 2011-06-19 03:53:32 PDT ---
This program fails to compile

import std.stdio;

void main()
{
   string foo = "foo";
   string bar = "bar";

   string mrX;

   switch(mrX)
   {
      case foo:
         writeln(foo);
         break;
      case bar:
         writeln(bar);
         break;
      default:
         writeln("who knows");
   }
}


giving this error:

prog.d(12): Error: case must be a string or an integral constant, not foo

If you change the variables to int, then it works, but it doesn't work with
strings.

According to TDPL, p. 72, "Usually case expressions are compile-time constants,
but D allows variables too and guarantees lexical-order evaluation up to the
first match." So, according to TDPL, this code should be valid, but it
currently fails.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list