Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Eclipse sometimes warn about arrays of arrays in JavaScript?

In Eclipse, the following line of JavaScript

var a1 = [[1, 2], [3, 4]];

generates the warnings:

Type mismatch: cannot convert from Number[] to any
Type mismatch: cannot convert from Number[] to any

while

var a2 = [['w', 'x'], ['y', 'z']];

generates:

Type mismatch: cannot convert from String[] to any
Type mismatch: cannot convert from String[] to any

and

var a3 = [[1, 2], ['y', 'z']];

generates:

Type mismatch: cannot convert from Number[] to any
Type mismatch: cannot convert from String[] to any

However, these lines are all okay:

var a4 = [[1, 'x'], [3, 'y']];
var a5 = [[1, 2]];
var a6 = [['x', 'y']];

There seems to be a problem with arrays of arrays, when the sub-arrays contain the same primitive type. However, I don't understand why, and the code seems to execute okay. Can someone explain what Eclipse is worried about?

like image 815
Charles Anderson Avatar asked Nov 02 '11 09:11

Charles Anderson


1 Answers

It looks like a bug. There is essentially no such thing as a type mismatch in Javascript.

I would hazard a guess that the parser that is doing this was based on a Java parser, and this is a bit of that original parser peeking through.

like image 64
Paul Butcher Avatar answered Oct 19 '22 11:10

Paul Butcher