Bug 202936 - [compiler] Compiler error for Java switch expression provides inaccurate list of allowed data types
Summary: [compiler] Compiler error for Java switch expression provides inaccurate list...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.4 M2   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-11 11:12 EDT by Peter Mularien CLA
Modified: 2007-09-18 06:00 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Mularien CLA 2007-09-11 11:12:15 EDT
Build ID: I20070625-1500

Steps To Reproduce:
Write a simple switch statement with an invalid switch expression. e.g.:
		boolean t = true;
		switch(t) {
		case 1:
			System.out.println("1");
			break;
		}

The error message generated by the Eclipse compiler is:
"Cannot switch on a value of type boolean. Only int values or enum constants are permitted"

More information:
In fact, this error message isn't entirely accurate. As per the JLS, there are more permitted values than just int and enum constants. Ref. JLS 14.11:

"The type of the Expression must be char, byte, short, int, Character, Byte, Short, Integer, or an enum type (ยง8.9), or a compile-time error occurs."

The second sentence of the error message should be updated to reflect the full range of allowed data types in a switch expression.
Comment 1 Philipe Mulet CLA 2007-09-13 04:52:42 EDT
Note that wrapper types are only allowed in Java5... I'd vote for a less specific error message which would fit all scenarii.

"Cannot switch on a value of type boolean. Only int convertible values or enum constants are permitted"

Kent ? (if you agree pls perform the change in 3.4 stream, and update the tests if any)
Comment 2 Kent Johnson CLA 2007-09-13 12:55:11 EDT
Changed to

"Cannot switch on a value of type boolean. Only convertible int values or enum
constants are permitted"

Fixed up SwitchTests.test010()
Comment 3 Jerome Lanneluc CLA 2007-09-18 06:00:33 EDT
Verified for 3.4M2 using I20070917-0010