From 5bfe6cd20a99d36341cb1c237b8a3e2057fc9e02 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Mon, 28 Mar 2022 16:11:18 +0300 Subject: [PATCH] [FE] Implement discussed rules to report empty intersection errors --- .../ConstraintSystemCompletionContext.kt | 50 +++++++++++++++++-- .../generic/explicitTypeArguments.fir.kt | 2 +- .../generic/explicitTypeArguments.kt | 2 +- .../postponedArgumentsAnalysis/basic.fir.kt | 10 ++-- .../postponedArgumentsAnalysis/basic.kt | 10 ++-- .../diagnostics/tests/inference/kt48935.kt | 3 +- .../diagnostics/tests/inference/kt48935_2.kt | 13 +++++ .../diagnostics/tests/inference/kt48935_2.txt | 16 ++++++ .../tests/inference/kt48935_3.fir.kt | 11 ++++ .../diagnostics/tests/inference/kt48935_3.kt | 11 ++++ .../diagnostics/tests/inference/kt48935_3.txt | 18 +++++++ .../{kt48935.fir.kt => kt48935_4.fir.kt} | 4 +- .../diagnostics/tests/inference/kt48935_4.kt | 11 ++++ .../diagnostics/tests/inference/kt48935_4.txt | 18 +++++++ .../diagnostics/tests/inference/kt48935_5.kt | 13 +++++ .../diagnostics/tests/inference/kt48935_5.txt | 17 +++++++ .../diagnostics/tests/inference/kt48935_6.kt | 13 +++++ .../diagnostics/tests/inference/kt48935_6.txt | 17 +++++++ .../inference/selectOfLambdaWithExtension.kt | 2 +- .../selectOfLambdaWithExtensionDisabled.kt | 2 +- .../resolve/overloadConflicts/kt37692.fir.kt | 14 ------ .../resolve/overloadConflicts/kt37692.kt | 1 + .../specialConstructions/elvisAsCall.fir.kt | 2 +- .../specialConstructions/elvisAsCall.kt | 2 +- .../exclExclAsCall.fir.kt | 2 +- .../specialConstructions/exclExclAsCall.kt | 2 +- .../testsWithStdLib/greater.fir.kt | 12 +++++ .../diagnostics/testsWithStdLib/greater.kt | 5 +- .../kotlin/types/model/TypeSystemContext.kt | 20 -------- 29 files changed, 241 insertions(+), 62 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/kt48935_2.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt48935_2.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt48935_3.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt48935_3.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt48935_3.txt rename compiler/testData/diagnostics/tests/inference/{kt48935.fir.kt => kt48935_4.fir.kt} (87%) create mode 100644 compiler/testData/diagnostics/tests/inference/kt48935_4.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt48935_4.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt48935_5.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt48935_5.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt48935_6.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt48935_6.txt delete mode 100644 compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt37692.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/greater.fir.kt diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt index 278d621cdb4..13a048089b1 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintSystemCompletionContext.kt @@ -8,12 +8,12 @@ package org.jetbrains.kotlin.resolve.calls.inference.components import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder +import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.model.PostponedAtomWithRevisableExpectedType import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker -import org.jetbrains.kotlin.types.model.KotlinTypeMarker -import org.jetbrains.kotlin.types.model.TypeConstructorMarker -import org.jetbrains.kotlin.types.model.TypeVariableMarker +import org.jetbrains.kotlin.types.AbstractTypeChecker.isRelatedBySubtypingTo +import org.jetbrains.kotlin.types.model.* abstract class ConstraintSystemCompletionContext : VariableFixationFinder.Context, ResultTypeResolver.Context { abstract val allTypeVariables: Map @@ -37,6 +37,50 @@ abstract class ConstraintSystemCompletionContext : VariableFixationFinder.Contex abstract fun couldBeResolvedWithUnrestrictedBuilderInference(): Boolean abstract fun processForkConstraints() + private fun TypeConstructorMarker.isDefinitelyClass() = isClassTypeConstructor() && !isInterface() + + private fun KotlinTypeMarker.containsTypeParameter() = contains { it.typeConstructor().isTypeParameterTypeConstructor() } + + fun Collection.isEmptyIntersection(constraintSystem: NewConstraintSystem?): Boolean { + val indexedComponents = withIndex() + return indexedComponents.any firstTypes@{ (i, first) -> + val firstTypeConstructor = first.typeConstructor() + indexedComponents.any secondTypes@{ (j, second) -> + if (i >= j) return@secondTypes false + + val secondTypeConstructor = second.typeConstructor() + + if (!firstTypeConstructor.isDefinitelyClass() && !firstTypeConstructor.isTypeParameterTypeConstructor()) + return@secondTypes false + if (!secondTypeConstructor.isDefinitelyClass() && !secondTypeConstructor.isTypeParameterTypeConstructor()) + return@secondTypes false + + if (!first.containsTypeParameter() && !second.containsTypeParameter()) { + return@secondTypes !isRelatedBySubtypingTo(this@ConstraintSystemCompletionContext, first, second) + } + + if (constraintSystem == null) return false + + val completerContext = constraintSystem.asConstraintSystemCompleterContext() + val substitutionMap = completerContext.allTypeVariables.entries.associate { (key, value) -> + val typeParameter = (key as TypeVariableTypeConstructorMarker).typeParameter + require(typeParameter != null) { + "Constraint system for checking type parameters for intersection emptiness" + + "should be build with type variables which refer to those type parameters" + } + typeParameter.getTypeConstructor() to value.defaultType() + } + val substitutor = typeSubstitutorByTypeConstructor(substitutionMap) + + completerContext.getBuilder().addSubtypeConstraint( + substitutor.safeSubstitute(first), substitutor.safeSubstitute(second), TypeParametersIntersectionEmptyCheckingPosition + ) + + constraintSystem.hasContradiction + } + } + } + fun analyzeArgumentWithFixedParameterTypes( languageVersionSettings: LanguageVersionSettings, postponedArguments: List, diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/explicitTypeArguments.fir.kt b/compiler/testData/diagnostics/tests/callableReference/generic/explicitTypeArguments.fir.kt index efa93ce7aec..746705ae582 100644 --- a/compiler/testData/diagnostics/tests/callableReference/generic/explicitTypeArguments.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/generic/explicitTypeArguments.fir.kt @@ -18,7 +18,7 @@ fun test() { callFun>(::createWrapper) callFun>(::createWrapper) callFun>(::createWrapper) - callFun>(::createWrapper) + callFun>(::createWrapper) callFun>(::createWrapper).baz(::foo) } diff --git a/compiler/testData/diagnostics/tests/callableReference/generic/explicitTypeArguments.kt b/compiler/testData/diagnostics/tests/callableReference/generic/explicitTypeArguments.kt index fe61c362c4c..593f17ef28d 100644 --- a/compiler/testData/diagnostics/tests/callableReference/generic/explicitTypeArguments.kt +++ b/compiler/testData/diagnostics/tests/callableReference/generic/explicitTypeArguments.kt @@ -18,7 +18,7 @@ fun test() { callFun>(::createWrapper) callFun>(::createWrapper) callFun>(::createWrapper) - callFun>(::createWrapper) + callFun>(::createWrapper) callFun>(::createWrapper).baz(::foo) } diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt index 2e5fa6c12bd..59bbc661e66 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt @@ -70,7 +70,7 @@ fun main() { select(id1 { it.inv() }, id1 { x: Number -> TODO() }, id1(id2 { x: Int -> x })) select(id1 { it.inv() }, id1 { x: Number -> TODO() }, id1(id2(::takeInt))) select(id1 { x: Inv -> TODO() }, id1 { ")!>it.x.inv() }, id1 { x: Inv -> TODO() }) - select(id1 { & Inv")!>it }, id1 { x: Inv -> TODO() }, id1 { x: Inv -> TODO() }) + select(id1 { & Inv")!>it }, id1 { x: Inv -> TODO() }, id1 { x: Inv -> TODO() }) select(id(id2 { it.inv() }), id(id { x: Int -> x })) // Disambiguating callable references by other callable references without overloads @@ -164,10 +164,10 @@ fun main() { select({ x, y -> x.inv() + y.toByte() }, id { x: Int, y -> y.toByte() }, id { x, y: Number -> x.inv() }) // Inferring lambda parameter types by other specified lambda parameters; expected type is a functional type with type variables in parameter types - takeLambdas({ it }, { x: Int -> }, { x: Nothing -> x }) - takeLambdas({ it }, { } as (Int) -> Unit, { x: Nothing -> x }) - takeLambdas({ it }, { } as (Nothing) -> Unit, { x: Int -> x }) - takeLambdas({ it }, { } as (Int) -> Unit, { } as (Nothing) -> Unit) + takeLambdas({ it }, { x: Int -> }, { x: Nothing -> x }) + takeLambdas({ it }, { } as (Int) -> Unit, { x: Nothing -> x }) + takeLambdas({ it }, { } as (Nothing) -> Unit, { x: Int -> x }) + takeLambdas({ it }, { } as (Int) -> Unit, { } as (Nothing) -> Unit) // Inferring lambda parameter types by other specified lambda parameters; expected type is a functional type with type variables in parameter types; dependent type parameters takeLambdasWithDirectlyDependentTypeParameters({ it }, { it }, { x: Int -> x }) diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.kt index f50aa730101..5d643c914a0 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.kt @@ -70,7 +70,7 @@ fun main() { select(id1 { it.inv() }, id1 { x: Number -> TODO() }, id1(id2 { x: Int -> x })) select(id1 { it.inv() }, id1 { x: Number -> TODO() }, id1(id2(::takeInt))) select(id1 { x: Inv -> TODO() }, id1 { ")!>it.x.inv() }, id1 { x: Inv -> TODO() }) - select(id1 { & Inv}")!>it }, id1 { x: Inv -> TODO() }, id1 { x: Inv -> TODO() }) + select(id1 { & Inv}")!>it }, id1 { x: Inv -> TODO() }, id1 { x: Inv -> TODO() }) select(id(id2 { it.inv() }), id(id { x: Int -> x })) // Disambiguating callable references by other callable references without overloads @@ -164,10 +164,10 @@ fun main() { select({ x, y -> x.inv() + y.toByte() }, id { x: Int, y -> y.toByte() }, id { x, y: Number -> x.inv() }) // Inferring lambda parameter types by other specified lambda parameters; expected type is a functional type with type variables in parameter types - takeLambdas({ it }, { x: Int -> }, { x: Nothing -> x }) - takeLambdas({ it }, { } as (Int) -> Unit, { x: Nothing -> x }) - takeLambdas({ it }, { } as (Nothing) -> Unit, { x: Int -> x }) - takeLambdas({ it }, { } as (Int) -> Unit, { } as (Nothing) -> Unit) + takeLambdas({ it }, { x: Int -> }, { x: Nothing -> x }) + takeLambdas({ it }, { } as (Int) -> Unit, { x: Nothing -> x }) + takeLambdas({ it }, { } as (Nothing) -> Unit, { x: Int -> x }) + takeLambdas({ it }, { } as (Int) -> Unit, { } as (Nothing) -> Unit) // Inferring lambda parameter types by other specified lambda parameters; expected type is a functional type with type variables in parameter types; dependent type parameters takeLambdasWithDirectlyDependentTypeParameters({ it }, { it }, { x: Int -> x }) diff --git a/compiler/testData/diagnostics/tests/inference/kt48935.kt b/compiler/testData/diagnostics/tests/inference/kt48935.kt index 11c67aa1443..eed86cb45c9 100644 --- a/compiler/testData/diagnostics/tests/inference/kt48935.kt +++ b/compiler/testData/diagnostics/tests/inference/kt48935.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // RENDER_DIAGNOSTICS_FULL_TEXT interface Base @@ -9,5 +10,5 @@ fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { fun main() { val func: (DoesNotImplementBase) -> Unit = { } - exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied + exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt48935_2.kt b/compiler/testData/diagnostics/tests/inference/kt48935_2.kt new file mode 100644 index 00000000000..9cb247000df --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48935_2.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +interface Base + +interface DoesNotImplementBase + +fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { + +} + +fun main() { + val func: (DoesNotImplementBase) -> Unit = { } + exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt48935_2.txt b/compiler/testData/diagnostics/tests/inference/kt48935_2.txt new file mode 100644 index 00000000000..1ffaae327c8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48935_2.txt @@ -0,0 +1,16 @@ +package + +public fun kotlin.Unit> exampleGenericFunction(/*0*/ func: V): kotlin.Unit +public fun main(): kotlin.Unit + +public interface Base { + 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 DoesNotImplementBase { + 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/testData/diagnostics/tests/inference/kt48935_3.fir.kt b/compiler/testData/diagnostics/tests/inference/kt48935_3.fir.kt new file mode 100644 index 00000000000..6d46a76d6e1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48935_3.fir.kt @@ -0,0 +1,11 @@ +open class Base +open class DoesNotImplementBase + +fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { + +} + +fun main() { + val func: (DoesNotImplementBase) -> Unit = { } + exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt48935_3.kt b/compiler/testData/diagnostics/tests/inference/kt48935_3.kt new file mode 100644 index 00000000000..6d707f0aa1a --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48935_3.kt @@ -0,0 +1,11 @@ +open class Base +open class DoesNotImplementBase + +fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { + +} + +fun main() { + val func: (DoesNotImplementBase) -> Unit = { } + exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt48935_3.txt b/compiler/testData/diagnostics/tests/inference/kt48935_3.txt new file mode 100644 index 00000000000..9cbf388aae8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48935_3.txt @@ -0,0 +1,18 @@ +package + +public fun kotlin.Unit> exampleGenericFunction(/*0*/ func: V): kotlin.Unit +public fun main(): kotlin.Unit + +public open class Base { + public constructor Base() + 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 open class DoesNotImplementBase { + public constructor DoesNotImplementBase() + 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/testData/diagnostics/tests/inference/kt48935.fir.kt b/compiler/testData/diagnostics/tests/inference/kt48935_4.fir.kt similarity index 87% rename from compiler/testData/diagnostics/tests/inference/kt48935.fir.kt rename to compiler/testData/diagnostics/tests/inference/kt48935_4.fir.kt index d7e2cdfc5dc..86c6aea199c 100644 --- a/compiler/testData/diagnostics/tests/inference/kt48935.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/kt48935_4.fir.kt @@ -1,6 +1,4 @@ -// RENDER_DIAGNOSTICS_FULL_TEXT -interface Base - +open class Base class DoesNotImplementBase fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { diff --git a/compiler/testData/diagnostics/tests/inference/kt48935_4.kt b/compiler/testData/diagnostics/tests/inference/kt48935_4.kt new file mode 100644 index 00000000000..51b8c289d08 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48935_4.kt @@ -0,0 +1,11 @@ +open class Base +class DoesNotImplementBase + +fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { + +} + +fun main() { + val func: (DoesNotImplementBase) -> Unit = { } + exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt48935_4.txt b/compiler/testData/diagnostics/tests/inference/kt48935_4.txt new file mode 100644 index 00000000000..2b336827c31 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48935_4.txt @@ -0,0 +1,18 @@ +package + +public fun kotlin.Unit> exampleGenericFunction(/*0*/ func: V): kotlin.Unit +public fun main(): kotlin.Unit + +public open class Base { + public constructor Base() + 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 final class DoesNotImplementBase { + public constructor DoesNotImplementBase() + 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/testData/diagnostics/tests/inference/kt48935_5.kt b/compiler/testData/diagnostics/tests/inference/kt48935_5.kt new file mode 100644 index 00000000000..9822d12bf7d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48935_5.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +interface Base + +class DoesNotImplementBase + +fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { + +} + +fun main() { + val func: (DoesNotImplementBase) -> Unit = { } + exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt48935_5.txt b/compiler/testData/diagnostics/tests/inference/kt48935_5.txt new file mode 100644 index 00000000000..cd6c9b82779 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48935_5.txt @@ -0,0 +1,17 @@ +package + +public fun kotlin.Unit> exampleGenericFunction(/*0*/ func: V): kotlin.Unit +public fun main(): kotlin.Unit + +public interface Base { + 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 final class DoesNotImplementBase { + public constructor DoesNotImplementBase() + 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/testData/diagnostics/tests/inference/kt48935_6.kt b/compiler/testData/diagnostics/tests/inference/kt48935_6.kt new file mode 100644 index 00000000000..3f2c5e37bf5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48935_6.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +interface Base + +open class DoesNotImplementBase + +fun exampleGenericFunction(func: V) where T: Base, V: (T) -> Unit { + +} + +fun main() { + val func: (DoesNotImplementBase) -> Unit = { } + exampleGenericFunction(func) // expected this to be a compilation error as the T: Base constraint should not be satisfied +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt48935_6.txt b/compiler/testData/diagnostics/tests/inference/kt48935_6.txt new file mode 100644 index 00000000000..04ea833872c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt48935_6.txt @@ -0,0 +1,17 @@ +package + +public fun kotlin.Unit> exampleGenericFunction(/*0*/ func: V): kotlin.Unit +public fun main(): kotlin.Unit + +public interface Base { + 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 open class DoesNotImplementBase { + public constructor DoesNotImplementBase() + 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/testData/diagnostics/tests/inference/selectOfLambdaWithExtension.kt b/compiler/testData/diagnostics/tests/inference/selectOfLambdaWithExtension.kt index 1dc1c78bba5..5815056609c 100644 --- a/compiler/testData/diagnostics/tests/inference/selectOfLambdaWithExtension.kt +++ b/compiler/testData/diagnostics/tests/inference/selectOfLambdaWithExtension.kt @@ -14,7 +14,7 @@ val a1: A = select( { a: Int -> myPrint(a + this.length + 2) } ) -val a2 = select( +val a2 = select( { a: Int -> myPrint(a + this.length + 1) }, fun CharSequence.(a: Int) { myPrint(a + this.length + 2) }, { a: Int -> myPrint(a + this.length + 3) } diff --git a/compiler/testData/diagnostics/tests/inference/selectOfLambdaWithExtensionDisabled.kt b/compiler/testData/diagnostics/tests/inference/selectOfLambdaWithExtensionDisabled.kt index b054460a767..549d54327fa 100644 --- a/compiler/testData/diagnostics/tests/inference/selectOfLambdaWithExtensionDisabled.kt +++ b/compiler/testData/diagnostics/tests/inference/selectOfLambdaWithExtensionDisabled.kt @@ -14,7 +14,7 @@ val a1: A = select( { a: Int -> myPrint(a + this.length + 2) } ) -val a2 = select( +val a2 = select( { a: Int -> myPrint(a + this.length + 1) }, fun CharSequence.(a: Int) { myPrint(a + this.length + 2) }, { a: Int -> myPrint(a + this.length + 3) } diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt37692.fir.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt37692.fir.kt deleted file mode 100644 index 3edb4997dc0..00000000000 --- a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt37692.fir.kt +++ /dev/null @@ -1,14 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -abstract class Bar - -class Foo : Bar(), Comparable> { - override fun compareTo(other: Foo<*>): Int = TODO() -} - -infix fun , S : T?> Bar.test(t: T) { } -infix fun , S : T?> Bar.test(other: Bar) {} - -fun checkFunctions(exp1: Foo, exp2: Foo) { - exp1.test(exp2) -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt37692.kt b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt37692.kt index c5380625e81..c46866b6139 100644 --- a/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt37692.kt +++ b/compiler/testData/diagnostics/tests/resolve/overloadConflicts/kt37692.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER abstract class Bar diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.fir.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.fir.kt index 4f0327d961b..ecc4fe08214 100644 --- a/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.fir.kt @@ -13,7 +13,7 @@ fun testElvis(a: Int?, b: Int?) { if (a != null) { doInt(b ?: a) } - doList(getList() ?: emptyListOfA()) //should be an error + doList(getList() ?: emptyListOfA()) //should be an error doList(getList() ?: strangeList { doInt(it) }) //lambda was not analyzed } diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.kt index ffe2855f8f9..cb44030c595 100644 --- a/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.kt +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.kt @@ -13,7 +13,7 @@ fun testElvis(a: Int?, b: Int?) { if (a != null) { doInt(b ?: a) } - doList(getList() ?: emptyListOfA()) //should be an error + doList(getList() ?: emptyListOfA()) //should be an error doList(getList() ?: strangeList { doInt(it) }) //lambda was not analyzed } diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt index 808c42324ad..9ab0c68ba6d 100644 --- a/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.fir.kt @@ -12,7 +12,7 @@ fun emptyNullableListOfA(): List? = null //------------------------------- fun testExclExcl() { - doList(emptyNullableListOfA()!!) //should be an error here + doList(emptyNullableListOfA()!!) //should be an error here val l: List = id(emptyNullableListOfA()!!) doList(strangeNullableList { doInt(it) }!!) //lambda should be analyzed (at completion phase) diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.kt index 645cb0bf721..52d11c382ca 100644 --- a/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.kt +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/exclExclAsCall.kt @@ -12,7 +12,7 @@ fun emptyNullableListOfA(): List? = null //------------------------------- fun testExclExcl() { - doList(emptyNullableListOfA()!!) //should be an error here + doList(emptyNullableListOfA()!!) //should be an error here val l: List = id(emptyNullableListOfA()!!) doList(strangeNullableList { doInt(it) }!!) //lambda should be analyzed (at completion phase) diff --git a/compiler/testData/diagnostics/testsWithStdLib/greater.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/greater.fir.kt new file mode 100644 index 00000000000..c35bfb899a3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/greater.fir.kt @@ -0,0 +1,12 @@ +class Expression(val x: T) + +class GreaterOp(val expr1: Expression<*>, val expr2: Expression<*>) + +fun , S : T?> Expression.greater(other: T): GreaterOp = + GreaterOp(this, Expression(other)) + +fun foo(countExpr: Expression) { + countExpr.greater(0) + countExpr.greater("0") + countExpr.greater("0") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/greater.kt b/compiler/testData/diagnostics/testsWithStdLib/greater.kt index 31625fc9ffd..905c2dbd495 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/greater.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/greater.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL class Expression(val x: T) class GreaterOp(val expr1: Expression<*>, val expr2: Expression<*>) @@ -8,6 +7,6 @@ fun , S : T?> Expression.greater(other: T): GreaterOp = fun foo(countExpr: Expression) { countExpr.greater(0) - countExpr.greater("0") - countExpr.greater("0") + countExpr.greater("0") + countExpr.greater("0") } diff --git a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt index d77a9dd6b3c..956126df3ce 100644 --- a/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt +++ b/core/compiler.common/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt @@ -178,26 +178,6 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui fun KotlinTypeMarker.isFinal(): Boolean - fun Collection.isEmptyIntersection(): Boolean { - val expandedTypes = buildSet { - for (type in this@isEmptyIntersection) { - val typeConstructor = type.typeConstructor() - when { - typeConstructor.isClassTypeConstructor() -> add(type) - typeConstructor.isTypeParameterTypeConstructor() -> addAll(typeConstructor.supertypes()) - } - } - }.takeIf { it.isNotEmpty() } ?: return false - - return expandedTypes.any { first -> - expandedTypes.any { second -> - first !== second && - first.isFinal() && - !AbstractTypeChecker.isSubtypeOf(this@TypeSystemInferenceExtensionContext, first, second) - } - } - } - fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker