From 2fc79856a242a15638b2df61573bce7efbd09b98 Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Wed, 11 Dec 2019 16:20:43 +0300 Subject: [PATCH] [NI] Fix OnlyInputTypes for captured types Uncapture projections recursively for cases when captured type is not top-level type or first level type argument --- .../annotationsForResolve/kt35210.kt | 12 ++++++++++ .../annotationsForResolve/kt35210.txt | 11 ++++++++++ .../DiagnosticsTestWithStdLibGenerated.java | 5 +++++ ...ticsTestWithStdLibUsingJavacGenerated.java | 5 +++++ .../org/jetbrains/kotlin/types/TypeUtils.kt | 22 ++++++++++++++----- 5 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.txt diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.kt new file mode 100644 index 00000000000..8c7d8deca67 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") + +annotation class Anno + +fun test(a: List>) { + strictSelect(a, emptyList().map { it.annotationClass.java }) +} + +fun <@kotlin.internal.OnlyInputTypes S> strictSelect(arg1: S, arg2: S): S = TODO() \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.txt new file mode 100644 index 00000000000..2da28bf67ea --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.txt @@ -0,0 +1,11 @@ +package + +public fun strictSelect(/*0*/ arg1: S, /*1*/ arg2: S): S +public fun test(/*0*/ a: kotlin.collections.List>): kotlin.Unit + +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 +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 1a7b0a92356..2f5c5672487 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -2798,6 +2798,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt29307.kt"); } + @TestMetadata("kt35210.kt") + public void testKt35210() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.kt"); + } + @TestMetadata("noInferAndLowPriority.kt") public void testNoInferAndLowPriority() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAndLowPriority.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index c348491f8ab..cc7bcba8472 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -2798,6 +2798,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt29307.kt"); } + @TestMetadata("kt35210.kt") + public void testKt35210() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/kt35210.kt"); + } + @TestMetadata("noInferAndLowPriority.kt") public void testNoInferAndLowPriority() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAndLowPriority.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt index 5f7781fdc7c..6737585bad3 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt @@ -265,15 +265,25 @@ fun UnwrappedType.unCapture(): UnwrappedType = when (this) { } fun SimpleType.unCapture(): UnwrappedType { + if (this is ErrorType) return this if (this is NewCapturedType) return unCaptureTopLevelType() - val newArguments = arguments.map { projection -> - projection.type.constructor.safeAs()?.let { - it.projection - } ?: projection - } - return replace(newArguments) + val newArguments = arguments.map(::unCaptureProjection) + return replace(newArguments).unwrap() +} + +fun unCaptureProjection(projection: TypeProjection): TypeProjection { + val unCapturedProjection = projection.type.constructor.safeAs()?.let { + it.projection + } ?: projection + if (unCapturedProjection.type is ErrorType) return unCapturedProjection + + val newArguments = unCapturedProjection.type.arguments.map(::unCaptureProjection) + return TypeProjectionImpl( + unCapturedProjection.projectionKind, + unCapturedProjection.type.replace(newArguments) + ) } fun AbbreviatedType.unCapture(): SimpleType {