D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3376 - [tdpl] Multiple ranged case labels don't work
Summary: [tdpl] Multiple ranged case labels don't work
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-08 12:00 UTC by Andrei Alexandrescu
Modified: 2015-06-09 05:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrei Alexandrescu 2009-10-08 12:00:23 UTC
void classify(char c) {
   write("You passed ");
   switch (c) {
      case '#': 
         writeln("a hash sign."); 
         break;
      case '0': .. case '9': 
         writeln("a digit."); 
         break;
      case 'A': .. case 'Z': case 'a' .. case 'z': 
         writeln("an ASCII character."); 
         break;
      case '.', ',', ':', ';', '!', '?': 
         writeln("a punctuation mark."); 
         break;
      default:
         writeln("quite a character!");
         break;
   }
}

The code fails to compile. If I change the line:

      case 'A': .. case 'Z': case 'a' .. case 'z': 

to:

      case 'A': .. case 'Z':

then it compiles.
Comment 1 Rainer Schuetze 2009-10-16 15:09:11 UTC
>      case 'A': .. case 'Z': case 'a' .. case 'z': 

I'd say you have simply forgotten the colon after 'a'. With

>      case 'A': .. case 'Z': case 'a': .. case 'z': 

it compiles.
Comment 2 Andrei Alexandrescu 2009-10-16 15:15:41 UTC
(In reply to comment #1)
> >      case 'A': .. case 'Z': case 'a' .. case 'z': 
> 
> I'd say you have simply forgotten the colon after 'a'. With
> 
> >      case 'A': .. case 'Z': case 'a': .. case 'z': 
> 
> it compiles.

Ouch. This is rather ironic in wake of the fact that I preached the helpfulness of that ':'. Thanks, and apologies to everyone for the distraction.