#48 String .length() bug

open
Josson Smith
5
2009-08-22
2009-08-22
Sebastián Gurin
No

thw following code throws the error "Error: cs.length is not a function":

CharSequence cs = new String("he").subSequence(0,1);
cs.length();

I think this is due because of "".length() is translated to "".length when referencing strings but not when referencing a supertype like CharSequences. For example, see the following code and translated code below:

CharSequence cs = new String("he").subSequence(0,1);
cs.length(); //error
String s = "";
s.length(); //OK

javascript generated code:

var cs = String.instantialize ("he").subSequence (0, 1);
cs.length ();
var s = "";
s.length;

I think the same bug will occurs with other CharSequences than String.

Discussion