[JVM_IR] Trim the expression test string for null assertions.

^KT-47166 Fixed.
This commit is contained in:
Mads Ager
2021-06-11 14:54:20 +02:00
committed by teamcityserver
parent 58adfd8488
commit 6b6ba77869
6 changed files with 58 additions and 1 deletions
@@ -26408,6 +26408,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/notNullAssertions/doGenerateParamAssertions.kt");
}
@Test
@TestMetadata("messageLength.kt")
public void testMessageLength() throws Exception {
runTest("compiler/testData/codegen/box/notNullAssertions/messageLength.kt");
}
@Test
@TestMetadata("noCallAssertions.kt")
public void testNoCallAssertions() throws Exception {
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.backend.jvm.lower
import com.intellij.openapi.util.text.StringUtil
import org.jetbrains.kotlin.backend.common.FileLoweringPass
import org.jetbrains.kotlin.backend.common.lower.IrBuildingTransformer
import org.jetbrains.kotlin.backend.common.lower.at
@@ -422,7 +423,7 @@ private class TypeOperatorLowering(private val context: JvmBackendContext) : Fil
irComposite(resultType = expression.type) {
+irCall(checkExpressionValueIsNotNull).apply {
putValueArgument(0, irGet(valueSymbol.owner))
putValueArgument(1, irString(source))
putValueArgument(1, irString(source.trimForRuntimeAssertion()))
}
+irGet(valueSymbol.owner)
}
@@ -436,6 +437,8 @@ private class TypeOperatorLowering(private val context: JvmBackendContext) : Fil
}
}
private fun String.trimForRuntimeAssertion() = StringUtil.trimMiddle(this, 50)
private fun IrFunction.isDelegated() =
origin == IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR ||
origin == IrDeclarationOrigin.DELEGATED_MEMBER
@@ -0,0 +1,31 @@
// TARGET_BACKEND: JVM
// FILE: test.kt
fun test(): String {
return A()
// Large comment that would cause the message for
// the non-null assertion to be very large if
// it is included verbatim in the message.
.foo()
}
fun box(): String {
try {
test()
} catch(e: Throwable) {
return if (e.message!!.length <= " must not be null".length + 50) {
"OK"
} else {
"FAIL1"
}
}
return "FAIL2"
}
// FILE: A.java
public class A {
public String foo() {
return null;
}
}
@@ -26372,6 +26372,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/notNullAssertions/doGenerateParamAssertions.kt");
}
@Test
@TestMetadata("messageLength.kt")
public void testMessageLength() throws Exception {
runTest("compiler/testData/codegen/box/notNullAssertions/messageLength.kt");
}
@Test
@TestMetadata("noCallAssertions.kt")
public void testNoCallAssertions() throws Exception {
@@ -26408,6 +26408,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/notNullAssertions/doGenerateParamAssertions.kt");
}
@Test
@TestMetadata("messageLength.kt")
public void testMessageLength() throws Exception {
runTest("compiler/testData/codegen/box/notNullAssertions/messageLength.kt");
}
@Test
@TestMetadata("noCallAssertions.kt")
public void testNoCallAssertions() throws Exception {
@@ -22344,6 +22344,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/notNullAssertions/doGenerateParamAssertions.kt");
}
@TestMetadata("messageLength.kt")
public void testMessageLength() throws Exception {
runTest("compiler/testData/codegen/box/notNullAssertions/messageLength.kt");
}
@TestMetadata("noCallAssertions.kt")
public void testNoCallAssertions() throws Exception {
runTest("compiler/testData/codegen/box/notNullAssertions/noCallAssertions.kt");