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
@@ -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
}