diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/internalAnnotationsOnTypes.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/internalAnnotationsOnTypes.kt index 59e5422611d..86a57e0c766 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/internalAnnotationsOnTypes.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/internalAnnotationsOnTypes.kt @@ -1,13 +1,30 @@ +//!DIAGNOSTICS: -UNUSED_PARAMETER + @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") fun Iterable<*>.filterIsInstance1(): List<@kotlin.internal.NoInfer R> = throw Exception() +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun List<*>.filterIsInstance2(): @kotlin.internal.NoInfer List = throw Exception() + fun test(list: List) { - list.filterIsInstance1().map { it * 2} + list.filterIsInstance1().map { it * 2 } + list.filterIsInstance2().filter { it > 10 } } @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") fun foo(t: R): List<@kotlin.internal.NoInfer R> = throw Exception("$t") fun test() { - foo(1).map { it * 2} + foo(1).map { it * 2 } +} + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun List.foo(): @kotlin.internal.NoInfer R = throw Exception() + +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +fun bar(r: R, f: Function1<@kotlin.internal.NoInfer R, Unit>): Nothing = throw Exception() + +fun test1() { + listOf("").foo().length + bar(1) { x -> x + 1 } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/internalAnnotationsOnTypes.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/internalAnnotationsOnTypes.txt index bb3a67f8a10..b2f3a015d90 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/internalAnnotationsOnTypes.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/internalAnnotationsOnTypes.txt @@ -1,6 +1,10 @@ package +@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun bar(/*0*/ r: R, /*1*/ f: (R) -> kotlin.Unit): kotlin.Nothing @kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun foo(/*0*/ t: R): kotlin.List public fun test(): kotlin.Unit public fun test(/*0*/ list: kotlin.List): kotlin.Unit +public fun test1(): kotlin.Unit @kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun kotlin.Iterable<*>.filterIsInstance1(): kotlin.List +@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun kotlin.List<*>.filterIsInstance2(): kotlin.List +@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun kotlin.List.foo(): R diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java b/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java index 8b335b32d51..58ba9d4f0d5 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeSubstitutor.java @@ -240,7 +240,7 @@ public class TypeSubstitutor { return containedOrCapturedTypeParameters.contains(key.getConstructor()) ? substitution.get(key) : null; } }; - KotlinType substitutedType = KotlinTypeImpl.create(type.getAnnotations(), // Old annotations. This is questionable + KotlinType substitutedType = KotlinTypeImpl.create(substitution.filterAnnotations(type.getAnnotations()), // Old annotations. This is questionable type.getConstructor(), // The same constructor type.isMarkedNullable(), // Same nullability substitutedArguments, diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt index 58230a5ab53..7f8604524e8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/TypeUtils.kt @@ -101,7 +101,7 @@ fun TypeProjection.substitute(doSubstitute: (KotlinType) -> KotlinType): TypePro } fun KotlinType.replaceAnnotations(newAnnotations: Annotations): KotlinType { - if (newAnnotations.isEmpty()) return this + if (annotations.isEmpty() && newAnnotations.isEmpty()) return this return object : DelegatingType() { override fun getDelegate() = this@replaceAnnotations