Bug 335630 - [validation] Invalid errors on switch statement case expressions for mismatched types
Summary: [validation] Invalid errors on switch statement case expressions for mismatch...
Status: NEW
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: 3.2.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: Future   Edit
Assignee: Project Inbox CLA
QA Contact: Chris Jaun CLA
URL:
Whiteboard:
Keywords: plan
Depends on:
Blocks:
 
Reported: 2011-01-27 17:20 EST by Chris Jaun CLA
Modified: 2014-05-29 13:52 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 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 ;)