From c31573466578386ca76cabaea8168745b1180ca9 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 12 Mar 2012 16:57:43 +0400 Subject: [PATCH] EA-34240 - SIOOBE: CompileTimeConstantResolver.getCharValue --- .../constants/CompileTimeConstantResolver.java | 4 ++-- .../diagnostics/tests/CharacterLiterals.jet | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/CharacterLiterals.jet diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/CompileTimeConstantResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/CompileTimeConstantResolver.java index febee59455a..0fa2aa91a7d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/CompileTimeConstantResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/CompileTimeConstantResolver.java @@ -182,11 +182,11 @@ public class CompileTimeConstantResolver { } // Strip the quotes - if (text.charAt(0) != '\'' || text.charAt(text.length() - 1) != '\'') { + if (text.length() < 2 || text.charAt(0) != '\'' || text.charAt(text.length() - 1) != '\'') { return new ErrorValue("Incorrect character literal"); } text = text.substring(1, text.length() - 1); // now there're no quotes - + if (text.length() == 0) { return new ErrorValue("Empty character literal"); } diff --git a/compiler/testData/diagnostics/tests/CharacterLiterals.jet b/compiler/testData/diagnostics/tests/CharacterLiterals.jet new file mode 100644 index 00000000000..9942668c574 --- /dev/null +++ b/compiler/testData/diagnostics/tests/CharacterLiterals.jet @@ -0,0 +1,13 @@ +fun test(c : Char) { + test('') + test('a') + test('aa') + test('a) + test(' + test(0' + test('\n') + test('\\') + test('''') + test('\'') + test('\"') +}