enhancements in character constant parsing

* missing assertion converted to ErrorValue
* added test for 'a
* '\' must be error (KT-461)
This commit is contained in:
Stepan Koltsov
2011-11-10 16:16:31 +04:00
parent dda5759643
commit 44b631cdd0
2 changed files with 13 additions and 3 deletions
@@ -164,14 +164,21 @@ public class CompileTimeConstantResolver {
if (error != null) {
return error;
}
assert text.charAt(0) == '\'' && text.charAt(text.length() - 1) == '\'';
if (text.charAt(0) != '\'' || text.charAt(text.length() - 1) != '\'') {
return new ErrorValue("Incorret character constant");
}
text = text.substring(1, text.length() - 1);
if (text.length() == 0) {
return new ErrorValue("Empty character literal");
} else if (text.length() == 1) {
return new CharValue(text.charAt(0));
if (text.charAt(0) == '\\') {
return new ErrorValue("Illegal escape: " + text);
} else {
return new CharValue(text.charAt(0));
}
} else if (text.length() == 2 && text.charAt(0) == '\\') {
Character escaped = translateEscape(text.charAt(1));
if (escaped == null) {
@@ -4,6 +4,9 @@
fun ff() {
val b = <!ERROR_COMPILE_TIME_VALUE!>''<!>
val c = <!ERROR_COMPILE_TIME_VALUE!>'23'<!>
val d = <!ERROR_COMPILE_TIME_VALUE!>'a<!>
val e = <!ERROR_COMPILE_TIME_VALUE!>'ab<!>
val f = <!ERROR_COMPILE_TIME_VALUE!>'\'<!>
}
fun test() {
@@ -20,4 +23,4 @@ fun test() {
<!ERROR_COMPILE_TIME_VALUE!>'\123'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\ra'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\000'<!>
}
}