From 42af684ab7c4de3d337345a69de6c9356d77c5f9 Mon Sep 17 00:00:00 2001 From: Vladimir Sukharev Date: Thu, 21 Sep 2023 13:53:52 +0200 Subject: [PATCH] [FIR] Fix disappeared ILLEGAL_ESCAPE ^KT-59950 Fixed --- .../fir/builder/AbstractRawFirBuilder.kt | 16 ++++++++++---- .../diagnostics/tests/StringTemplates.fir.kt | 22 ------------------- .../diagnostics/tests/StringTemplates.kt | 1 + 3 files changed, 13 insertions(+), 26 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/StringTemplates.fir.kt diff --git a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilder.kt b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilder.kt index 8bf67feeaf6..0fbf945b22f 100644 --- a/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilder.kt +++ b/compiler/fir/raw-fir/raw-fir.common/src/org/jetbrains/kotlin/fir/builder/AbstractRawFirBuilder.kt @@ -514,8 +514,15 @@ abstract class AbstractRawFirBuilder(val baseSession: FirSession, val context } ESCAPE_STRING_TEMPLATE_ENTRY -> { sb.append(entry.unescapedValue) - buildConstExpression( - entry.toFirSourceElement(), ConstantValueKind.String, entry.unescapedValue, setType = false + val characterWithDiagnostic = escapedStringToCharacter(entry.asText) + buildConstOrErrorExpression( + entry.toFirSourceElement(), + ConstantValueKind.Char, + characterWithDiagnostic.value, + ConeSimpleDiagnostic( + "Incorrect character: ${entry.asText}", + characterWithDiagnostic.getDiagnostic() ?: DiagnosticKind.IllegalConstExpression + ) ) } SHORT_STRING_TEMPLATE_ENTRY, LONG_STRING_TEMPLATE_ENTRY -> { @@ -533,8 +540,9 @@ abstract class AbstractRawFirBuilder(val baseSession: FirSession, val context } } source = base?.toFirSourceElement() - // Fast-pass if there is no non-const string expressions - if (!hasExpressions) return buildConstExpression(source, ConstantValueKind.String, sb.toString(), setType = false) + // Fast-pass if there is no errors and non-const string expressions + if (!hasExpressions && !argumentList.arguments.any { it is FirErrorExpression }) + return buildConstExpression(source, ConstantValueKind.String, sb.toString(), setType = false) } } diff --git a/compiler/testData/diagnostics/tests/StringTemplates.fir.kt b/compiler/testData/diagnostics/tests/StringTemplates.fir.kt deleted file mode 100644 index 42ebed1181f..00000000000 --- a/compiler/testData/diagnostics/tests/StringTemplates.fir.kt +++ /dev/null @@ -1,22 +0,0 @@ -fun demo() { - val abc = 1 - val a = "" - val asd = 1 - val bar = 5 - fun map(f : () -> Any?) : Int = 1 - fun buzz(f : () -> Any?) : Int = 1 - val sdf = 1 - val foo = 3; - "$abc" - "$" - "$.$.asdf$\t" - "asd\$" - "asd$a\x" - "asd$a$asd$ $xxx" - "fosdfasdo${1 + bar + 100}}sdsdfgdsfsdf" - "foo${bar + map {foo}}sdfsdf" - "foo${bar + map { "foo" }}sdfsdf" - "foo${bar + map { - "foo$sdf${ buzz{}}" }}sdfsdf" - "a\u \u0 \u00 \u000 \u0000 \u0AaA \u0AAz.length( ) + \u0022b" -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/StringTemplates.kt b/compiler/testData/diagnostics/tests/StringTemplates.kt index a9e74ee2f28..96cf2460e0d 100644 --- a/compiler/testData/diagnostics/tests/StringTemplates.kt +++ b/compiler/testData/diagnostics/tests/StringTemplates.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL fun demo() { val abc = 1 val a = ""