enhancements in character constant parsing
* missing assertion converted to ErrorValue * added test for 'a * '\' must be error (KT-461)
This commit is contained in:
+9
-2
@@ -164,14 +164,21 @@ public class CompileTimeConstantResolver {
|
|||||||
if (error != null) {
|
if (error != null) {
|
||||||
return error;
|
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);
|
text = text.substring(1, text.length() - 1);
|
||||||
|
|
||||||
if (text.length() == 0) {
|
if (text.length() == 0) {
|
||||||
return new ErrorValue("Empty character literal");
|
return new ErrorValue("Empty character literal");
|
||||||
} else if (text.length() == 1) {
|
} 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) == '\\') {
|
} 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) {
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
fun ff() {
|
fun ff() {
|
||||||
val b = <!ERROR_COMPILE_TIME_VALUE!>''<!>
|
val b = <!ERROR_COMPILE_TIME_VALUE!>''<!>
|
||||||
val c = <!ERROR_COMPILE_TIME_VALUE!>'23'<!>
|
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() {
|
fun test() {
|
||||||
@@ -20,4 +23,4 @@ fun test() {
|
|||||||
<!ERROR_COMPILE_TIME_VALUE!>'\123'<!>
|
<!ERROR_COMPILE_TIME_VALUE!>'\123'<!>
|
||||||
<!ERROR_COMPILE_TIME_VALUE!>'\ra'<!>
|
<!ERROR_COMPILE_TIME_VALUE!>'\ra'<!>
|
||||||
<!ERROR_COMPILE_TIME_VALUE!>'\000'<!>
|
<!ERROR_COMPILE_TIME_VALUE!>'\000'<!>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user