Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 335630

Summary: [validation] Invalid errors on switch statement case expressions for mismatched types
Product: [WebTools] JSDT Reporter: Chris Jaun <cmjaun>
Component: GeneralAssignee: Project Inbox <jsdt.javascript-inbox>
Status: NEW --- QA Contact: Chris Jaun <cmjaun>
Severity: normal    
Priority: P3 CC: linzuxiong1988, zulus
Version: 3.2.3Keywords: plan
Target Milestone: Future   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Chris Jaun CLA 2011-01-27 17:20:38 EST
var n = "hi";
var a = [1, 3];
switch(n) {
case 1: //
case 2: //
case 'hi': //
case 'bye': //
case "hi": //
case 60 * 60: //
case Math.PI: //
case n + 1: //
case a[0]: //
}

Put that switch statement on a JavaScript page. You'll see a much of errors, for example:

Description	Resource	Path	Location	Type
Type mismatch: cannot convert from Number to String	script1.js	/JSProject	line 9	JavaScript Problem


To my knowledge, all of the expressions in that case are valid.
Comment 1 Lin ZuXiong CLA 2012-02-06 00:11:49 EST
I donot think the authors of JSDT know Javascript Language.

I suggest let us close the javascript validation. 
But eclipse jee 3.7.1 canot close JS validation.I close the Preference of
javascript validation and make the level be Ignore ,but eclipse Problems still 
reports the problems (errors and warnings) of Javascript type .

Guys , you all can import a js file ,like JQuery-1.x.min.js , so that you can
find too many errors.
Comment 2 Dawid Pakula CLA 2013-05-01 13:23:40 EDT
I think problem is on another place. Look at 2 tests:

1.

var n = 1.5;
switch (n) {
case 1/2:
   alert(1);
   break;
case 1/3:
   alert(2);
   break;
}

No errors now, but here:

2.

var n = 1;
switch (n) {
case 1/2:
   alert(1);
   break;
case 1/3:
   alert(2);
   break;
}

And you will get duplicate case error :/

In JavaScript switch/case statement , case expression is never casted to switch expresssion type.

As always sorry for my english ;)