Bug 352412

Summary: Switching on strings in 1.6- modes produces misleading message
Product: [Eclipse Project] JDT Reporter: Srikanth Sankaran <srikanth_sankaran>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P5 CC: amj87.iitr, stephan.herrmann
Version: 3.7   
Target Milestone: 3.8 M2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
proposed fix v1.0 + updated tests none

Description Srikanth Sankaran CLA 2011-07-19 04:25:26 EDT
BETA_JAVA7 branch.

"Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum constants are permitted" is the message
we issue when there is an attempt to switch on strings in source levels
1.6-.

The latter part of message is obviously incorrect, as you can switch
on a enum variable. In fact there is no reason why you would want to
switch on an enum constant.

The phrase "convertible int values" is also not particularly helpful.
Comment 1 Ayushman Jain CLA 2011-07-19 04:41:13 EDT
(In reply to comment #0)
> BETA_JAVA7 branch.
> 
> "Cannot switch on a value of type String for source level below 1.7. Only
> convertible int values or enum constants are permitted" is the message
> we issue when there is an attempt to switch on strings in source levels
> 1.6-.
> 
> The latter part of message is obviously incorrect, as you can switch
> on a enum variable. In fact there is no reason why you would want to
> switch on an enum constant.
> 
> The phrase "convertible int values" is also not particularly helpful.

Two things:
1) An identical warning is also seen for invalid switches for 1.6- where we're not switching on a string.
2) The part that says "convertible int values" sounds ok since we need to cover all the types that can be converted to an integral number, such as a char. So the following is still valid:
char c = 'a';
		switch(c) {
		case 'a':
		case 'b':
		}

Hence the bug comes down to changing "enum constants" to "enum variables".
Comment 2 Ayushman Jain CLA 2011-08-08 14:46:39 EDT
Created attachment 201099 [details]
proposed fix v1.0 + updated tests

Corrected all the switch related errors, replacing "enum constants" with "enum variables"
Comment 3 Ayushman Jain CLA 2011-08-09 10:33:15 EDT
Released in HEAD for 3.8M2
Comment 4 Stephan Herrmann CLA 2011-09-13 09:50:39 EDT
Verified for 3.8M2 using build I20110911-2000.