From fe04cc513b43666214eb96840bbb46003f9d04a9 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 30 Nov 2015 17:36:12 +0300 Subject: [PATCH] Original type is taken into account when intersecting possible types in resolve #KT-10232 Fixed --- .../resolve/calls/GenericCandidateResolver.kt | 2 +- .../tests/generics/nullability/smartCasts.kt | 2 +- .../diagnostics/tests/smartCasts/kt10232.kt | 15 +++++++++++++++ .../diagnostics/tests/smartCasts/kt10232.txt | 16 ++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 6 ++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt10232.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/kt10232.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt index c0a6e099756..c555a7728a1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/GenericCandidateResolver.kt @@ -197,7 +197,7 @@ class GenericCandidateResolver(private val argumentTypeResolver: ArgumentTypeRes val possibleTypes = context.dataFlowInfo.getPossibleTypes(dataFlowValue) if (possibleTypes.isEmpty()) return type - return TypeIntersector.intersectTypes(KotlinTypeChecker.DEFAULT, possibleTypes) + return TypeIntersector.intersectTypes(KotlinTypeChecker.DEFAULT, possibleTypes + type) } fun completeTypeInferenceDependentOnFunctionArgumentsForCall(context: CallCandidateResolutionContext) { diff --git a/compiler/testData/diagnostics/tests/generics/nullability/smartCasts.kt b/compiler/testData/diagnostics/tests/generics/nullability/smartCasts.kt index b2c3edb509b..3cab07bfe72 100644 --- a/compiler/testData/diagnostics/tests/generics/nullability/smartCasts.kt +++ b/compiler/testData/diagnostics/tests/generics/nullability/smartCasts.kt @@ -38,7 +38,7 @@ fun foo(x: T) { x.length x?.length - x.bar1() + x.bar1() x.bar2() x.bar3() } diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt10232.kt b/compiler/testData/diagnostics/tests/smartCasts/kt10232.kt new file mode 100644 index 00000000000..00840f11164 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt10232.kt @@ -0,0 +1,15 @@ +// Type inference failed after smart cast + +interface A +interface B : A + +fun foo(b: A) = b + +fun test(a: A) { + if (a is Any) { + // Error:(9, 9) Kotlin: Type inference failed: fun foo(b: A): kotlin.Unit + // cannot be applied to (A) + foo(a) + } + foo(a) // ok +} diff --git a/compiler/testData/diagnostics/tests/smartCasts/kt10232.txt b/compiler/testData/diagnostics/tests/smartCasts/kt10232.txt new file mode 100644 index 00000000000..a221c64faff --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/kt10232.txt @@ -0,0 +1,16 @@ +package + +public fun foo(/*0*/ b: A): A +public fun test(/*0*/ a: A): kotlin.Unit + +public interface A { + 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 +} + +public interface B : A { + 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/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index afffbb7277c..b3ae0fcb106 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -14742,6 +14742,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt10232.kt") + public void testKt10232() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/kt10232.kt"); + doTest(fileName); + } + @TestMetadata("kt1461.kt") public void testKt1461() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/kt1461.kt");