Don't save constant value for non-resolved array expression in K1

#KT-55912 Fixed
This commit is contained in:
Ivan Kylchik
2023-01-23 18:02:19 +01:00
committed by Space Team
parent 8fcea399f9
commit 13cad2a820
15 changed files with 89 additions and 13 deletions
@@ -17063,6 +17063,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/evaluate/intrinsics.kt");
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt55912.kt");
}
@Test
@TestMetadata("kt9443.kt")
public void testKt9443() throws Exception {
@@ -19,10 +19,7 @@ import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperClassifiers
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.typeUtil.isNothing
import org.jetbrains.kotlin.types.typeUtil.isTypeParameter
import org.jetbrains.kotlin.types.typeUtil.isUnit
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
import org.jetbrains.kotlin.types.typeUtil.*
private val javaLangCloneable = FqNameUnsafe("java.lang.Cloneable")
@@ -193,15 +190,6 @@ object ValueClassDeclarationChecker : DeclarationChecker {
private fun KotlinType.isInapplicableParameterType() =
isUnit() || isNothing()
private fun KotlinType.isGenericArrayOfTypeParameter(): Boolean {
if (!KotlinBuiltIns.isArray(this)) return false
val argument0 = arguments[0]
if (argument0.isStarProjection) return false
val argument0type = argument0.type
return argument0type.isTypeParameter() ||
argument0type.isGenericArrayOfTypeParameter()
}
private fun isParameterAcceptableForInlineClass(parameter: KtParameter): Boolean {
val isOpen = parameter.modalityModifier()?.node?.elementType == KtTokens.OPEN_KEYWORD
return parameter.hasValOrVar() && !parameter.isMutable && !parameter.isVarArg && !isOpen
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.types.expressions.DoubleColonLHS
import org.jetbrains.kotlin.types.expressions.OperatorConventions
import org.jetbrains.kotlin.types.isError
import org.jetbrains.kotlin.types.typeUtil.isBoolean
import org.jetbrains.kotlin.types.typeUtil.isGenericArrayOfTypeParameter
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
import org.jetbrains.kotlin.util.OperatorNameConventions
import java.math.BigInteger
@@ -408,6 +409,12 @@ private class ConstantExpressionEvaluatorVisitor(
if (shouldSkipComplexBooleanValue(expression, compileTimeConstant)) {
return null
}
// If constant is `Array` and its argument is some generic type, then we must wait for full resolve and only when we can record value
if (compileTimeConstant is TypedCompileTimeConstant && compileTimeConstant.type.isGenericArrayOfTypeParameter()) {
return compileTimeConstant
}
trace.record(BindingContext.COMPILE_TIME_VALUE, expression, compileTimeConstant)
return compileTimeConstant
}
+8
View File
@@ -0,0 +1,8 @@
public annotation class Entity(val foreignKeys: Array<String>)
@Entity(foreignKeys = kotlin.arrayOf("id")) // works without "kotlin."
class Record
fun box(): String {
return "OK"
}
@@ -16757,6 +16757,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/evaluate/intrinsics.kt");
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt55912.kt");
}
@Test
@TestMetadata("kt9443.kt")
public void testKt9443() throws Exception {
@@ -17063,6 +17063,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/evaluate/intrinsics.kt");
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt55912.kt");
}
@Test
@TestMetadata("kt9443.kt")
public void testKt9443() throws Exception {
@@ -13830,6 +13830,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/evaluate/intrinsics.kt");
}
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt55912.kt");
}
@TestMetadata("kt9443.kt")
public void testKt9443() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt9443.kt");
@@ -101,6 +101,15 @@ fun KotlinType?.isArrayOfNothing(): Boolean {
return typeArg != null && KotlinBuiltIns.isNothingOrNullableNothing(typeArg)
}
fun KotlinType.isGenericArrayOfTypeParameter(): Boolean {
if (!KotlinBuiltIns.isArray(this)) return false
val argument0 = arguments[0]
if (argument0.isStarProjection) return false
val argument0type = argument0.type
return argument0type.isTypeParameter() ||
argument0type.isGenericArrayOfTypeParameter()
}
fun KotlinType.isSubtypeOf(superType: KotlinType): Boolean = KotlinTypeChecker.DEFAULT.isSubtypeOf(this, superType)
@@ -12913,6 +12913,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/evaluate"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt55912.kt");
}
@Test
@TestMetadata("kt9443.kt")
public void testKt9443() throws Exception {
@@ -13009,6 +13009,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/evaluate"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt55912.kt");
}
@Test
@TestMetadata("kt9443.kt")
public void testKt9443() throws Exception {
@@ -13009,6 +13009,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/evaluate"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt55912.kt");
}
@Test
@TestMetadata("kt9443.kt")
public void testKt9443() throws Exception {
@@ -13009,6 +13009,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/evaluate"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt55912.kt");
}
@Test
@TestMetadata("kt9443.kt")
public void testKt9443() throws Exception {
@@ -11535,6 +11535,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/evaluate"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
}
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt55912.kt");
}
@TestMetadata("kt9443.kt")
public void testKt9443() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt9443.kt");
@@ -14188,6 +14188,12 @@ public class K2NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/evaluate"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt55912.kt");
}
@Test
@TestMetadata("kt9443.kt")
public void testKt9443() throws Exception {
@@ -14023,6 +14023,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/evaluate"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("kt55912.kt")
public void testKt55912() throws Exception {
runTest("compiler/testData/codegen/box/evaluate/kt55912.kt");
}
@Test
@TestMetadata("kt9443.kt")
public void testKt9443() throws Exception {