FIR: infer non-error types for unnamed annotation arguments

This commit is contained in:
pyos
2021-03-25 10:38:31 +01:00
committed by TeamCityServer
parent f2a892a972
commit 6c11751c55
@@ -549,10 +549,7 @@ internal fun JavaAnnotation.toFirAnnotationCall(
else -> buildArgumentMapping(session, javaTypeParameterStack, lookupTag!!, arguments) else -> buildArgumentMapping(session, javaTypeParameterStack, lookupTag!!, arguments)
} ?: buildArgumentList { } ?: buildArgumentList {
this@toFirAnnotationCall.arguments.mapTo(arguments) { this@toFirAnnotationCall.arguments.mapTo(arguments) {
val expectedArgumentType = buildErrorTypeRef { it.toFirExpression(session, javaTypeParameterStack, null)
diagnostic = ConeSimpleDiagnostic("java annotation argument without expected type")
}
it.toFirExpression(session, javaTypeParameterStack, expectedArgumentType)
} }
} }
calleeReference = FirReferencePlaceholderForResolvedAnnotations calleeReference = FirReferencePlaceholderForResolvedAnnotations
@@ -623,15 +620,17 @@ private fun JavaType?.toConeProjectionWithoutEnhancement(
} }
internal fun JavaAnnotationArgument.toFirExpression( internal fun JavaAnnotationArgument.toFirExpression(
session: FirSession, javaTypeParameterStack: JavaTypeParameterStack, expectedTypeRef: FirTypeRef session: FirSession, javaTypeParameterStack: JavaTypeParameterStack, expectedTypeRef: FirTypeRef?
): FirExpression { ): FirExpression {
return when (this) { return when (this) {
is JavaLiteralAnnotationArgument -> value.createConstantOrError(session) is JavaLiteralAnnotationArgument -> value.createConstantOrError(session)
is JavaArrayAnnotationArgument -> buildArrayOfCall { is JavaArrayAnnotationArgument -> buildArrayOfCall {
typeRef = expectedTypeRef val argumentTypeRef = expectedTypeRef?.let {
val argumentTypeRef = buildResolvedTypeRef { typeRef = it
type = expectedTypeRef.coneTypeSafe<ConeKotlinType>()?.lowerBoundIfFlexible()?.arrayElementType() buildResolvedTypeRef {
?: ConeClassErrorType(ConeSimpleDiagnostic("expected type is not array type")) type = it.coneTypeSafe<ConeKotlinType>()?.lowerBoundIfFlexible()?.arrayElementType()
?: ConeClassErrorType(ConeSimpleDiagnostic("expected type is not array type"))
}
} }
argumentList = buildArgumentList { argumentList = buildArgumentList {
getElements().mapTo(arguments) { it.toFirExpression(session, javaTypeParameterStack, argumentTypeRef) } getElements().mapTo(arguments) { it.toFirExpression(session, javaTypeParameterStack, argumentTypeRef) }