KT-451 Incorrect character literals cause assertion failures

''
'21'
This commit is contained in:
Stepan Koltsov
2011-11-10 15:05:07 +04:00
parent c03a256353
commit cd2dab3e53
@@ -167,19 +167,20 @@ public class CompileTimeConstantResolver {
assert text.charAt(0) == '\'' && text.charAt(text.length() - 1) == '\''; assert text.charAt(0) == '\'' && text.charAt(text.length() - 1) == '\'';
text = text.substring(1, text.length() - 1); text = text.substring(1, text.length() - 1);
assert text.length() < 3 && text.length() > 0;
if (text.length() == 2) { if (text.length() == 0) {
assert text.charAt(0) == '\\'; return new ErrorValue("Empty character literal");
} else if (text.length() == 1) {
return new CharValue(text.charAt(0));
} else if (text.length() == 2 && text.charAt(0) == '\\') {
Character escaped = translateEscape(text.charAt(1)); Character escaped = translateEscape(text.charAt(1));
if (escaped == null) { if (escaped == null) {
return new ErrorValue("Illegal escape: " + text); return new ErrorValue("Illegal escape: " + text);
} }
return new CharValue(escaped); return new CharValue(escaped);
} else {
return new ErrorValue("Too many characters in character literal");
} }
assert text.length() == 1;
return new CharValue(text.charAt(0));
} }
@Nullable @Nullable