diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt index 54f3e44289f..2dfecd8601d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt @@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.isUnderscoreNamed import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil import org.jetbrains.kotlin.resolve.scopes.* import org.jetbrains.kotlin.resolve.scopes.receivers.* +import org.jetbrains.kotlin.resolve.source.getPsi import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.expressions.* import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContext @@ -689,9 +690,14 @@ class PSICallResolver( val typeReference = projection.typeReference ?: return@map TypeArgumentPlaceholder if (typeReference.isPlaceholder) { - ForceResolveUtil.forceResolveAllContents( - typeResolver.resolveTypeAnnotations(context.trace, context.scope, typeReference) - ) + val resolvedAnnotations = typeResolver.resolveTypeAnnotations(context.trace, context.scope, typeReference) + .apply(ForceResolveUtil::forceResolveAllContents) + + for (annotation in resolvedAnnotations) { + val annotationElement = annotation.source.getPsi() ?: continue + context.trace.report(Errors.UNSUPPORTED.on(annotationElement, "annotations on an underscored type argument")) + } + return@map TypeArgumentPlaceholder } diff --git a/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt index 92db6a5a9d7..600d8a9ccae 100644 --- a/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt +++ b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.kt @@ -4,10 +4,24 @@ fun foo(x: (K) -> T): Pair = (1 as K) to (1f as T) +@Repeatable @Target(AnnotationTarget.TYPE) annotation class Anno +@Repeatable +@Target(AnnotationTarget.TYPE) +annotation class Anno2 + +@Repeatable +@Target(AnnotationTarget.TYPE) +annotation class Anno3(val x: String) + fun box(): String { - val x = foo<@Anno Int, @Anno _> { it.toFloat() } + val x = foo<@Anno Int, @Anno _> { it.toFloat() } + val y: Pair = foo<@[Anno Anno2] _, @Anno _> { it.toFloat() } + val z1: Pair = foo<@Anno @Anno2 /**/ _, @[/**/ Anno /**/ ] _> { it.toFloat() } + val z2: Pair = foo<@Anno3("") /**/ _, @[/**/ Anno /**/ Anno3("") /**/] _,> { it.toFloat() } + + val z3: Pair<@Anno3("") _, Float> = 1 to 1f return "OK" } diff --git a/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.txt b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.txt index aaa635e675b..b7a921e8319 100644 --- a/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.txt +++ b/compiler/testData/diagnostics/tests/inference/annotatedUnderscoredTypeArgument.txt @@ -3,9 +3,25 @@ package public fun box(): kotlin.String public fun foo(/*0*/ x: (K) -> T): kotlin.Pair -@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public final annotation class Anno : kotlin.Annotation { +@kotlin.annotation.Repeatable @kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public final annotation class Anno : kotlin.Annotation { public constructor Anno() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } + +@kotlin.annotation.Repeatable @kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public final annotation class Anno2 : kotlin.Annotation { + public constructor Anno2() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +@kotlin.annotation.Repeatable @kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public final annotation class Anno3 : kotlin.Annotation { + public constructor Anno3(/*0*/ x: kotlin.String) + public final val x: kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} +