From 26a96a1c19a193cd9c68b583c559967715d9e5c5 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Wed, 24 Feb 2021 16:29:12 +0300 Subject: [PATCH] Don't throw an exception while loading type use annotations on implicit bounds of a wildcard ^KT-45067 Fixed --- .../load/java/structure/impl/classFiles/Annotations.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Annotations.kt b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Annotations.kt index a6a5dd1e248..d89264b7efb 100644 --- a/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Annotations.kt +++ b/compiler/resolution.common.jvm/src/org/jetbrains/kotlin/load/java/structure/impl/classFiles/Annotations.kt @@ -174,7 +174,7 @@ class BinaryJavaAnnotation private constructor( } internal fun computeTargetType(baseType: JavaType, typePath: TypePath) = - translatePath(typePath).fold(baseType) { targetType, (typePathKind, typeArgumentIndex) -> + translatePath(typePath).fold, JavaType?>(baseType) { targetType, (typePathKind, typeArgumentIndex) -> when (typePathKind) { TypePath.TYPE_ARGUMENT -> { require(targetType is JavaClassifierType) @@ -182,10 +182,11 @@ class BinaryJavaAnnotation private constructor( ?: throw IllegalArgumentException("There must be no less than ${typeArgumentIndex + 1} type arguments") } TypePath.WILDCARD_BOUND -> { - // TODO: think about processing annotated wildcards themselves require(targetType is JavaWildcardType) + // below, returned `null` means annotated implicit lower and upper wildcard's bound, + // it isn't supported yet to load type use annotations (null is further ignored) + // TODO: consider taking into account such annotations through returning wildcard itself as a target type (KT-40498) targetType.bound - ?: throw IllegalArgumentException("Wildcard mast have a bound for annotation of WILDCARD_BOUND position") } TypePath.ARRAY_ELEMENT -> { require(targetType is JavaArrayType)