diff --git a/compiler/testData/diagnostics/tests/controlStructures/commonSupertypeOfT.kt b/compiler/testData/diagnostics/tests/controlStructures/commonSupertypeOfT.kt new file mode 100644 index 00000000000..7e959f31192 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/commonSupertypeOfT.kt @@ -0,0 +1,30 @@ +// KT-6774 Cannot find equals() when comparing with null + +fun fn(t1: T, t2: T?) { + val x = if (true) t1 else t2 + x == null + x?.equals(null) + x?.hashCode() + x.toString() + x!!.hashCode() + + val y = t2 ?: t1 + y == t1 + y.equals(null) + y.hashCode() + y.toString() + y.hashCode() +} + +trait Tr { + fun foo() +} + +fun fn(t1: T, t2: T?) { + val x = if (true) t1 else t2 + x?.foo() + x!!.foo() + + val y = t2 ?: t1 + y.foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/commonSupertypeOfT.txt b/compiler/testData/diagnostics/tests/controlStructures/commonSupertypeOfT.txt new file mode 100644 index 00000000000..8e5d48a2bab --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/commonSupertypeOfT.txt @@ -0,0 +1,11 @@ +package + +internal fun fn(/*0*/ t1: T, /*1*/ t2: T?): kotlin.Unit +internal fun fn(/*0*/ t1: T, /*1*/ t2: T?): kotlin.Unit + +internal trait Tr { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + internal abstract fun foo(): kotlin.Unit + 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/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index b91d44a0b6e..5cccf442aed 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -1950,6 +1950,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/controlStructures"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("commonSupertypeOfT.kt") + public void testCommonSupertypeOfT() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlStructures/commonSupertypeOfT.kt"); + doTest(fileName); + } + @TestMetadata("emptyIf.kt") public void testEmptyIf() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/CommonSupertypes.java b/core/descriptors/src/org/jetbrains/kotlin/types/CommonSupertypes.java index bdcbbf616a4..814bfd8d5f8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/CommonSupertypes.java +++ b/core/descriptors/src/org/jetbrains/kotlin/types/CommonSupertypes.java @@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.descriptors.ClassDescriptor; -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; +import org.jetbrains.kotlin.descriptors.ClassifierDescriptor; import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor; import org.jetbrains.kotlin.descriptors.annotations.Annotations; import org.jetbrains.kotlin.resolve.scopes.JetScope; @@ -223,12 +223,14 @@ public class CommonSupertypes { nullable |= type.isMarkedNullable(); } - // TODO : attributes? JetScope newScope = JetScope.Empty.INSTANCE$; - DeclarationDescriptor declarationDescriptor = constructor.getDeclarationDescriptor(); + ClassifierDescriptor declarationDescriptor = constructor.getDeclarationDescriptor(); if (declarationDescriptor instanceof ClassDescriptor) { newScope = ((ClassDescriptor) declarationDescriptor).getMemberScope(newProjections); } + else if (declarationDescriptor instanceof TypeParameterDescriptor) { + newScope = ((TypeParameterDescriptor) declarationDescriptor).getUpperBoundsAsType().getMemberScope(); + } return new JetTypeImpl(Annotations.EMPTY, constructor, nullable, newProjections, newScope); }