Use correct toString method in IrCompileTimeChecker for analysis
This commit is contained in:
+6
@@ -135,5 +135,11 @@ public class LoweredIrInterpreterTestGenerated extends AbstractLoweredIrInterpre
|
||||
public void testUnsignedConst() throws Exception {
|
||||
runTest("compiler/testData/ir/loweredIr/interpreter/unsignedConst.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("useCorrectToString.kt")
|
||||
public void testUseCorrectToString() throws Exception {
|
||||
runTest("compiler/testData/ir/loweredIr/interpreter/useCorrectToString.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ class IrCompileTimeChecker(
|
||||
is IrGetObjectValue -> {
|
||||
val toString = arg.symbol.owner.declarations
|
||||
.filterIsInstance<IrSimpleFunction>()
|
||||
.single { it.name.asString() == "toString" && it.valueParameters.isEmpty() }
|
||||
.single { it.name.asString() == "toString" && it.valueParameters.isEmpty() && it.extensionReceiverParameter == null }
|
||||
|
||||
mode.canEvaluateFunction(toString, null) && toString.visitBodyIfNeeded()
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ internal class Common private constructor(override val irClass: IrClass, overrid
|
||||
return irClass.declarations
|
||||
.filterIsInstance<IrSimpleFunction>()
|
||||
.single {
|
||||
it.name == Name.identifier("equals") && it.dispatchReceiverParameter != null
|
||||
it.name == Name.identifier("equals") && it.dispatchReceiverParameter != null && it.extensionReceiverParameter == null
|
||||
&& it.valueParameters.size == 1 && it.valueParameters[0].type.isNullableAny()
|
||||
}
|
||||
.let { it.resolveFakeOverride() as IrSimpleFunction }
|
||||
@@ -60,13 +60,13 @@ internal class Common private constructor(override val irClass: IrClass, overrid
|
||||
|
||||
fun getHashCodeFunction(): IrSimpleFunction {
|
||||
return irClass.declarations.filterIsInstance<IrSimpleFunction>()
|
||||
.single { it.name.asString() == "hashCode" && it.valueParameters.isEmpty() }
|
||||
.single { it.name.asString() == "hashCode" && it.valueParameters.isEmpty() && it.extensionReceiverParameter == null }
|
||||
.let { it.resolveFakeOverride() as IrSimpleFunction }
|
||||
}
|
||||
|
||||
fun getToStringFunction(): IrSimpleFunction {
|
||||
return irClass.declarations.filterIsInstance<IrSimpleFunction>()
|
||||
.single { it.name.asString() == "toString" && it.valueParameters.isEmpty() }
|
||||
.single { it.name.asString() == "toString" && it.valueParameters.isEmpty() && it.extensionReceiverParameter == null }
|
||||
.let { it.resolveFakeOverride() as IrSimpleFunction }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// This test is needed to check that IrCompileTimeChecker will not fail trying to find and analyze correct toString method
|
||||
|
||||
object Obj {
|
||||
override fun toString(): String = "OK"
|
||||
|
||||
fun Int.toString(): String = "Not OK"
|
||||
}
|
||||
|
||||
const val a = 1 // this is a dummy const to avoid check in IrInterpreterDumpHandler
|
||||
|
||||
fun box(): String {
|
||||
return "" + "$Obj" // force a call
|
||||
}
|
||||
Reference in New Issue
Block a user