K2: set vararg type for Java annotations #KT-59464 Fixed
This commit is contained in:
committed by
Space Team
parent
6f8e2b4718
commit
ba0ab38b83
+2
-2
@@ -204,8 +204,8 @@ class Fir2IrImplicitCastInserter(
|
|||||||
insertImplicitCasts()
|
insertImplicitCasts()
|
||||||
}
|
}
|
||||||
|
|
||||||
val valueType = valueTypeRef.coneTypeSafe<ConeKotlinType>()?.fullyExpandedType(session) ?: return this
|
val valueType = valueTypeRef.coneType.fullyExpandedType(session)
|
||||||
val expectedType = expectedTypeRef.coneTypeSafe<ConeKotlinType>()?.fullyExpandedType(session) ?: return this
|
val expectedType = expectedTypeRef.coneType.fullyExpandedType(session)
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
expectedType.isUnit -> {
|
expectedType.isUnit -> {
|
||||||
|
|||||||
+7
-1
@@ -95,7 +95,13 @@ internal class AnnotationsLoader(private val session: FirSession, private val ko
|
|||||||
|
|
||||||
override fun visitEnd() {
|
override fun visitEnd() {
|
||||||
visitExpression(name, buildArrayOfCall {
|
visitExpression(name, buildArrayOfCall {
|
||||||
guessArrayTypeIfNeeded(name, elements)?.let { typeRef = it }
|
guessArrayTypeIfNeeded(name, elements)?.let {
|
||||||
|
typeRef = it
|
||||||
|
} ?: elements.firstOrNull()?.typeRef?.coneType?.createOutArrayType()?.let {
|
||||||
|
typeRef = buildResolvedTypeRef {
|
||||||
|
type = it
|
||||||
|
}
|
||||||
|
}
|
||||||
argumentList = buildArgumentList {
|
argumentList = buildArgumentList {
|
||||||
arguments += elements
|
arguments += elements
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.fir.types.*
|
|||||||
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||||
|
import org.jetbrains.kotlin.fir.types.jvm.FirJavaTypeRef
|
||||||
import org.jetbrains.kotlin.load.java.structure.*
|
import org.jetbrains.kotlin.load.java.structure.*
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaElementImpl
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaElementImpl
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
@@ -88,7 +89,9 @@ internal fun JavaAnnotationArgument.toFirExpression(
|
|||||||
is JavaLiteralAnnotationArgument -> value.createConstantOrError(session)
|
is JavaLiteralAnnotationArgument -> value.createConstantOrError(session)
|
||||||
is JavaArrayAnnotationArgument -> buildArrayOfCall {
|
is JavaArrayAnnotationArgument -> buildArrayOfCall {
|
||||||
val argumentTypeRef = expectedTypeRef?.let {
|
val argumentTypeRef = expectedTypeRef?.let {
|
||||||
typeRef = it
|
typeRef = if (it is FirJavaTypeRef) buildResolvedTypeRef {
|
||||||
|
type = it.toConeKotlinTypeProbablyFlexible(session, javaTypeParameterStack)
|
||||||
|
} else it
|
||||||
buildResolvedTypeRef {
|
buildResolvedTypeRef {
|
||||||
type = it.coneTypeSafe<ConeKotlinType>()?.lowerBoundIfFlexible()?.arrayElementType()
|
type = it.coneTypeSafe<ConeKotlinType>()?.lowerBoundIfFlexible()?.arrayElementType()
|
||||||
?: ConeErrorType(ConeSimpleDiagnostic("expected type is not array type"))
|
?: ConeErrorType(ConeSimpleDiagnostic("expected type is not array type"))
|
||||||
@@ -184,13 +187,17 @@ private fun List<JavaAnnotationArgument>.mapJavaTargetArguments(session: FirSess
|
|||||||
}
|
}
|
||||||
val classId = StandardClassIds.AnnotationTarget
|
val classId = StandardClassIds.AnnotationTarget
|
||||||
resultSet.mapTo(arguments) { buildEnumCall(session, classId, Name.identifier(it.name)) }
|
resultSet.mapTo(arguments) { buildEnumCall(session, classId, Name.identifier(it.name)) }
|
||||||
|
val elementConeType = ConeClassLikeTypeImpl(
|
||||||
|
classId.toLookupTag(),
|
||||||
|
emptyArray(),
|
||||||
|
isNullable = false,
|
||||||
|
ConeAttributes.Empty
|
||||||
|
)
|
||||||
|
typeRef = buildResolvedTypeRef {
|
||||||
|
type = elementConeType
|
||||||
|
}
|
||||||
varargElementType = buildResolvedTypeRef {
|
varargElementType = buildResolvedTypeRef {
|
||||||
type = ConeClassLikeTypeImpl(
|
type = elementConeType.createOutArrayType()
|
||||||
classId.toLookupTag(),
|
|
||||||
emptyArray(),
|
|
||||||
isNullable = false,
|
|
||||||
ConeAttributes.Empty
|
|
||||||
).createOutArrayType()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user