diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt index effb55bab55..f00da01b565 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/NewTypeSubstitutor.kt @@ -46,13 +46,14 @@ interface NewTypeSubstitutor { if (type is AbbreviatedType) { val substitutedExpandedType = substitute(type.expandedType, keepAnnotation, runCapturedChecks) val substitutedAbbreviation = substitute(type.abbreviation, keepAnnotation, runCapturedChecks) - if (substitutedExpandedType is SimpleType? && substitutedAbbreviation is SimpleType?) { - return AbbreviatedType( - substitutedExpandedType ?: type.expandedType, - substitutedAbbreviation ?: type.abbreviation - ) - } else { - return substitutedExpandedType + return when { + substitutedExpandedType == null && substitutedAbbreviation == null -> null + substitutedExpandedType is SimpleType? && substitutedAbbreviation is SimpleType? -> + AbbreviatedType( + substitutedExpandedType ?: type.expandedType, + substitutedAbbreviation ?: type.abbreviation + ) + else -> substitutedExpandedType } } diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithInnerTypealias.kt b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithInnerTypealias.kt new file mode 100644 index 00000000000..f5a9613e048 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithInnerTypealias.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +NewInference + +import kotlin.reflect.KClass + +typealias MyString = String + +fun test(k: KClass) { + k::class.java +} + +@Suppress("UPPER_BOUND_VIOLATED") +public val KClass.java: Class get() = TODO() diff --git a/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithInnerTypealias.txt b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithInnerTypealias.txt new file mode 100644 index 00000000000..0547236928d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithInnerTypealias.txt @@ -0,0 +1,5 @@ +package + +@kotlin.Suppress(names = {"UPPER_BOUND_VIOLATED"}) public val kotlin.reflect.KClass.java: java.lang.Class +public fun test(/*0*/ k: kotlin.reflect.KClass): kotlin.Unit +public typealias MyString = kotlin.String diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 153e0f01c29..f4f3126903b 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -9396,6 +9396,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeSubstitutedIntoOppositeProjection.kt"); } + @TestMetadata("capturedTypeWithInnerTypealias.kt") + public void testCapturedTypeWithInnerTypealias() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithInnerTypealias.kt"); + } + @TestMetadata("capturedTypeWithTypeVariableSubtyping.kt") public void testCapturedTypeWithTypeVariableSubtyping() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithTypeVariableSubtyping.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 8ba970a92e7..c073d06c620 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -9396,6 +9396,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeSubstitutedIntoOppositeProjection.kt"); } + @TestMetadata("capturedTypeWithInnerTypealias.kt") + public void testCapturedTypeWithInnerTypealias() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithInnerTypealias.kt"); + } + @TestMetadata("capturedTypeWithTypeVariableSubtyping.kt") public void testCapturedTypeWithTypeVariableSubtyping() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/capturedTypes/capturedTypeWithTypeVariableSubtyping.kt");