Handle IllegalArgumentException in trimMargin intrinsics on JVM
#KT-38537 Fixed
This commit is contained in:
@@ -33,7 +33,11 @@ class TrimMargin : IntrinsicMethod() {
|
|||||||
val marginPrefix = argument.valueArgument?.getArgumentExpression()
|
val marginPrefix = argument.valueArgument?.getArgumentExpression()
|
||||||
?.let { codegen.getCompileTimeConstant(it) as? StringValue }
|
?.let { codegen.getCompileTimeConstant(it) as? StringValue }
|
||||||
?.value ?: return null
|
?.value ?: return null
|
||||||
literalText.trimMargin(marginPrefix)
|
try {
|
||||||
|
literalText.trimMargin(marginPrefix)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else -> error("Unknown value argument type ${argument::class}: $argument")
|
else -> error("Unknown value argument type ${argument::class}: $argument")
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+5
@@ -14501,6 +14501,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
public void testTostring() throws Exception {
|
public void testTostring() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/intrinsics/tostring.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/tostring.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("trimMarginWithBlankString.kt")
|
||||||
|
public void testTrimMarginWithBlankString() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/intrinsics/trimMarginWithBlankString.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/ir")
|
@TestMetadata("compiler/testData/codegen/box/ir")
|
||||||
|
|||||||
+5
-1
@@ -44,7 +44,11 @@ class StringTrimLowering(val context: CommonBackendContext) : FileLoweringPass,
|
|||||||
val prefixArgument = call.getValueArgument(0)
|
val prefixArgument = call.getValueArgument(0)
|
||||||
val newString = if (prefixArgument != null) {
|
val newString = if (prefixArgument != null) {
|
||||||
val prefixString = prefixArgument.getConstantString() ?: return call
|
val prefixString = prefixArgument.getConstantString() ?: return call
|
||||||
receiverString.trimMargin(prefixString)
|
try {
|
||||||
|
receiverString.trimMargin(prefixString)
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
return call
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
receiverString.trimMargin()
|
receiverString.trimMargin()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
// KJS_WITH_FULL_RUNTIME
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
try {
|
||||||
|
"a b c".trimMargin(" ")
|
||||||
|
return "Fail trimMargin"
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -15721,6 +15721,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
public void testTostring() throws Exception {
|
public void testTostring() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/intrinsics/tostring.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/tostring.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("trimMarginWithBlankString.kt")
|
||||||
|
public void testTrimMarginWithBlankString() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/intrinsics/trimMarginWithBlankString.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/ir")
|
@TestMetadata("compiler/testData/codegen/box/ir")
|
||||||
|
|||||||
+5
@@ -15721,6 +15721,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
public void testTostring() throws Exception {
|
public void testTostring() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/intrinsics/tostring.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/tostring.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("trimMarginWithBlankString.kt")
|
||||||
|
public void testTrimMarginWithBlankString() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/intrinsics/trimMarginWithBlankString.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/ir")
|
@TestMetadata("compiler/testData/codegen/box/ir")
|
||||||
|
|||||||
+5
@@ -14501,6 +14501,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
public void testTostring() throws Exception {
|
public void testTostring() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/intrinsics/tostring.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/tostring.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("trimMarginWithBlankString.kt")
|
||||||
|
public void testTrimMarginWithBlankString() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/intrinsics/trimMarginWithBlankString.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/ir")
|
@TestMetadata("compiler/testData/codegen/box/ir")
|
||||||
|
|||||||
Generated
+5
@@ -12621,6 +12621,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
public void testTostring() throws Exception {
|
public void testTostring() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/intrinsics/tostring.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/tostring.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("trimMarginWithBlankString.kt")
|
||||||
|
public void testTrimMarginWithBlankString() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/intrinsics/trimMarginWithBlankString.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/ir")
|
@TestMetadata("compiler/testData/codegen/box/ir")
|
||||||
|
|||||||
+5
@@ -12686,6 +12686,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
public void testTostring() throws Exception {
|
public void testTostring() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/intrinsics/tostring.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/tostring.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("trimMarginWithBlankString.kt")
|
||||||
|
public void testTrimMarginWithBlankString() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/intrinsics/trimMarginWithBlankString.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/box/ir")
|
@TestMetadata("compiler/testData/codegen/box/ir")
|
||||||
|
|||||||
Reference in New Issue
Block a user