diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/upperBoundViolated.txt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/upperBoundViolated.txt index f0c353ed66f..d86d58149e4 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/upperBoundViolated.txt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/upperBoundViolated.txt @@ -26,8 +26,8 @@ FILE: upperBoundViolated.kt lval b5: R|B| = R|/B.B|<>() R|/fest|() R|/fest|() - R|/fest|() - R|/fest||>() + R|/fest|() + R|/fest|() } public open class S : R|kotlin/Any| { public constructor(): R|S| { diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/concurrentMapOfAliases.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/concurrentMapOfAliases.txt index 5b463950d0a..7b052d75048 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/concurrentMapOfAliases.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/concurrentMapOfAliases.txt @@ -5,11 +5,11 @@ FILE: concurrentMapOfAliases.kt super() } - private final val foo: R|java/util/concurrent/ConcurrentHashMap!, ft!>| = Q|java/util/concurrent|.R|java/util/concurrent/ConcurrentHashMap.ConcurrentHashMap|!|, R|ft!|>() - private get(): R|java/util/concurrent/ConcurrentHashMap!, ft!>| + private final val foo: R|java/util/concurrent/ConcurrentHashMap!, ft!>| = Q|java/util/concurrent|.R|java/util/concurrent/ConcurrentHashMap.ConcurrentHashMap|!|, R|ft!|>() + private get(): R|java/util/concurrent/ConcurrentHashMap!, ft!>| private final fun bar(): R|kotlin/Unit| { - this@R|/A|.R|/A.foo|.R|FakeOverride|(String(dd))?.{ (this@R|/A|, $subj$).R|/A.baz|() } + this@R|/A|.R|/A.foo|.R|FakeOverride|(String(dd))?.{ (this@R|/A|, $subj$).R|/A.baz|() } } private final fun R|MyAlias|.baz(): R|kotlin/Unit| { diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java index 32864ce6244..b7ed11dc909 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestWithStdlibGenerated.java @@ -3023,6 +3023,29 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi runTest("compiler/testData/diagnostics/testsWithStdLib/inference/recursiveFlexibleAssertions.kt"); } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AddEqualityConstraintsWithoutSubtyping extends AbstractFirOldFrontendDiagnosticsTestWithStdlib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInAddEqualityConstraintsWithoutSubtyping() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("kt41741.kt") + public void testKt41741() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.kt"); + } + + @TestMetadata("kt42195.kt") + public void testKt42195() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.kt"); + } + } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/AbstractTypeCheckerContextForConstraintSystem.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/AbstractTypeCheckerContextForConstraintSystem.kt index 422bf4945da..d1a0df2ab40 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/AbstractTypeCheckerContextForConstraintSystem.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/AbstractTypeCheckerContextForConstraintSystem.kt @@ -34,6 +34,8 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck isFromNullabilityConstraint: Boolean = false ) + abstract fun addEqualityConstraint(typeVariable: TypeConstructorMarker, type: KotlinTypeMarker) + override fun getLowerCapturedTypePolicy(subType: SimpleTypeMarker, superType: CapturedTypeMarker): LowerCapturedTypePolicy { return when { isMyTypeVariable(subType) -> { diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt index 020f6e0d88d..d326bc8e34c 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintIncorporator.kt @@ -40,15 +40,19 @@ class ConstraintIncorporator( fun addNewIncorporatedConstraint(typeVariable: TypeVariableMarker, type: KotlinTypeMarker, constraintContext: ConstraintContext) } - fun incorporateIntoOtherConstraints(c: Context, typeVariable: TypeVariableMarker, constraint: Constraint) { + fun incorporateEqualityConstraint(c: Context, typeVariable: TypeVariableMarker, constraint: Constraint) = with(c) { // we shouldn't incorporate recursive constraint -- It is too dangerous if (c.areThereRecursiveConstraints(typeVariable, constraint)) return + c.directWithVariable(typeVariable, constraint) + if (constraint.type.contains { it is TypeVariableTypeConstructorMarker }) { + c.otherInsideMyConstraint(typeVariable, constraint) + } c.insideOtherConstraint(typeVariable, constraint) } // \alpha is typeVariable, \beta -- other type variable registered in ConstraintStorage - fun incorporate(c: Context, typeVariable: TypeVariableMarker, constraint: Constraint) { + fun incorporateSubtypeConstraint(c: Context, typeVariable: TypeVariableMarker, constraint: Constraint) { // we shouldn't incorporate recursive constraint -- It is too dangerous if (c.areThereRecursiveConstraints(typeVariable, constraint)) return diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt index f4e5d634464..ef8c250af0d 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt @@ -39,28 +39,42 @@ class ConstraintInjector( fun addInitialSubtypeConstraint(c: Context, lowerType: KotlinTypeMarker, upperType: KotlinTypeMarker, position: ConstraintPosition) { val initialConstraint = InitialConstraint(lowerType, upperType, UPPER, position).also { c.addInitialConstraint(it) } + val typeCheckerContext = TypeCheckerContext(c, IncorporationConstraintPosition(position, initialConstraint)) updateAllowedTypeDepth(c, lowerType) updateAllowedTypeDepth(c, upperType) - addSubTypeConstraintAndIncorporateIt( - c, - lowerType, - upperType, - TypeCheckerContext(c, IncorporationConstraintPosition(position, initialConstraint)) - ) + addSubTypeConstraintAndIncorporateIt(c, lowerType, upperType, typeCheckerContext) } - fun addInitialEqualityConstraint(c: Context, a: KotlinTypeMarker, b: KotlinTypeMarker, position: ConstraintPosition) { - val initialConstraint = InitialConstraint(a, b, EQUALITY, position).also { c.addInitialConstraint(it) } - - updateAllowedTypeDepth(c, a) - updateAllowedTypeDepth(c, b) + private fun Context.addInitialEqualityConstraintThroughSubtyping( + a: KotlinTypeMarker, + b: KotlinTypeMarker, + typeCheckerContext: TypeCheckerContext + ) { + updateAllowedTypeDepth(this, a) + updateAllowedTypeDepth(this, b) + addSubTypeConstraintAndIncorporateIt(this, a, b, typeCheckerContext) + addSubTypeConstraintAndIncorporateIt(this, b, a, typeCheckerContext) + } + fun addInitialEqualityConstraint(c: Context, a: KotlinTypeMarker, b: KotlinTypeMarker, position: ConstraintPosition) = with(c) { + val (typeVariable, equalType) = when { + a.typeConstructor(c) is TypeVariableTypeConstructorMarker -> a to b + b.typeConstructor(c) is TypeVariableTypeConstructorMarker -> b to a + else -> return + } + val initialConstraint = InitialConstraint(typeVariable, equalType, EQUALITY, position).also { c.addInitialConstraint(it) } val typeCheckerContext = TypeCheckerContext(c, IncorporationConstraintPosition(position, initialConstraint)) - addSubTypeConstraintAndIncorporateIt(c, a, b, typeCheckerContext) - addSubTypeConstraintAndIncorporateIt(c, b, a, typeCheckerContext) + // We add constraints like `T? == Foo!` in the old way + if (!typeVariable.isSimpleType() || typeVariable.isMarkedNullable()) { + addInitialEqualityConstraintThroughSubtyping(typeVariable, equalType, typeCheckerContext) + return + } + + updateAllowedTypeDepth(c, equalType) + addEqualityConstraintAndIncorporateIt(c, typeVariable, equalType, typeCheckerContext) } private fun addSubTypeConstraintAndIncorporateIt( @@ -72,6 +86,26 @@ class ConstraintInjector( typeCheckerContext.setConstrainingTypesToPrintDebugInfo(lowerType, upperType) typeCheckerContext.runIsSubtypeOf(lowerType, upperType) + processConstraints(c, typeCheckerContext, constraintIncorporator::incorporateSubtypeConstraint) + } + + private fun addEqualityConstraintAndIncorporateIt( + c: Context, + typeVariable: KotlinTypeMarker, + equalType: KotlinTypeMarker, + typeCheckerContext: TypeCheckerContext + ) { + typeCheckerContext.setConstrainingTypesToPrintDebugInfo(typeVariable, equalType) + typeCheckerContext.addEqualityConstraint(typeVariable.typeConstructor(c), equalType) + + processConstraints(c, typeCheckerContext, constraintIncorporator::incorporateEqualityConstraint) + } + + private fun processConstraints( + c: Context, + typeCheckerContext: TypeCheckerContext, + incorporate: (c: TypeCheckerContext, typeVariable: TypeVariableMarker, constraint: Constraint) -> Unit + ) { while (typeCheckerContext.hasConstraintsToProcess()) { for ((typeVariable, constraint) in typeCheckerContext.extractAllConstraints()!!) { if (c.shouldWeSkipConstraint(typeVariable, constraint)) continue @@ -82,7 +116,7 @@ class ConstraintInjector( // it is important, that we add constraint here(not inside TypeCheckerContext), because inside incorporation we read constraints constraints.addConstraint(constraint)?.let { if (!constraint.isNullabilityConstraint) { - constraintIncorporator.incorporate(typeCheckerContext, typeVariable, it) + incorporate(typeCheckerContext, typeVariable, it) } } } @@ -105,7 +139,8 @@ class ConstraintInjector( } private fun Context.shouldWeSkipConstraint(typeVariable: TypeVariableMarker, constraint: Constraint): Boolean { - assert(constraint.kind != EQUALITY) + if (constraint.kind == EQUALITY) + return false val constraintType = constraint.type @@ -221,6 +256,10 @@ class ConstraintInjector( isFromNullabilityConstraint: Boolean ) = addConstraint(typeVariable, subType, LOWER, isFromNullabilityConstraint) + override fun addEqualityConstraint(typeVariable: TypeConstructorMarker, type: KotlinTypeMarker) { + addConstraint(typeVariable, type, EQUALITY, false) + } + private fun isCapturedTypeFromSubtyping(type: KotlinTypeMarker) = when ((type as? CapturedTypeMarker)?.captureStatus()) { null, CaptureStatus.FROM_EXPRESSION -> false diff --git a/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt b/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt index 88ac6c4adcd..5d206d7ecd1 100644 --- a/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt +++ b/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt @@ -48,7 +48,7 @@ fun bar(a: Any): T = a as T fun foo() { foo<Color.RED>() - foo() + foo<RedAlias>() bar<Color.RED>(Color.RED) } diff --git a/compiler/testData/diagnostics/tests/MultipleBounds.kt b/compiler/testData/diagnostics/tests/MultipleBounds.kt index 94fdcfe0db6..bb249955ac3 100644 --- a/compiler/testData/diagnostics/tests/MultipleBounds.kt +++ b/compiler/testData/diagnostics/tests/MultipleBounds.kt @@ -62,7 +62,7 @@ fun test2(t : T) t.bar() } -val t1 = test2<A>(A()) +val t1 = test2<A>(A()) val t2 = test2<B>(C()) val t3 = test2(C()) diff --git a/compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirectionError.kt b/compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirectionError.kt index 9d3affdae3b..f3966713ecb 100644 --- a/compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirectionError.kt +++ b/compiler/testData/diagnostics/tests/callableReference/constraintFromLHSWithCorrectDirectionError.kt @@ -15,5 +15,5 @@ fun B.foo(p: KProperty1) {} class C : A fun B.test(){ - foo(C::bla) + foo(C::bla) } diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.kt index 980d12bf2b7..59217dfffc7 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.kt @@ -7,7 +7,7 @@ fun main() { val x1 = select(id { x, y -> }, { x: Int, y -> }) val x2 = select(id { x, y -> }, { x: Int, y -> }) - val x3 = select(id(fun (x, y) {}), fun (x: Int, y) {}) + val x3 = select(id(fun (x, y) {}), fun (x: Int, y) {}) val x4 = select((fun (x, y) {}), fun (x: Int, y) {}) val x5 = select(id(fun (x, y) {}), fun (x: Int, y) {}) diff --git a/compiler/testData/diagnostics/tests/inference/kt39220.kt b/compiler/testData/diagnostics/tests/inference/kt39220.kt index e1616522aa3..678a75270b4 100644 --- a/compiler/testData/diagnostics/tests/inference/kt39220.kt +++ b/compiler/testData/diagnostics/tests/inference/kt39220.kt @@ -27,20 +27,20 @@ interface Foo { // CR on property with to receivers are forbidden fun test() { // with LHS and property - bar8(Foo::x1) + bar8(Foo::x1) bar8(Foo::x1) bar8(Foo::x1) // with LHS and mutable property - bar8(Foo::x2) + bar8(Foo::x2) bar8(Foo::x2) bar8(Foo::x2) // with LHS and propery + mutable property (mixed) - bar8(Foo::x3) + bar8(Foo::x3) bar8(Foo::x3) bar8(Foo::x3) - bar9(Foo::x3) + bar9(Foo::x3) bar9(Foo::x3) bar9(Foo::x3) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.kt new file mode 100644 index 00000000000..d1efd92c4d1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.kt @@ -0,0 +1,37 @@ +// FIR_IDENTICAL +// FILE: Simple.java +// FULL_JDK +// WITH_RUNTIME +// !DIAGNOSTICS: -UNUSED_PARAMETER -CAST_NEVER_SUCCEEDS -UNUSED_VARIABLE + +import java.util.*; +import java.util.function.Supplier; + +public class Simple> { + public Simple(Map backingMap, Supplier innerCollectionCreator) { + // TODO + } + public final void add(K key, V value) { + //TODO + } + public static class ListSimple extends Simple, List> { + public ListSimple(Map> backingMap, Supplier> innerCollectionCreator) { + super(backingMap, innerCollectionCreator); + } + } +} + +// FILE: main.kt +import java.util.* + +fun , B: Simple> Iterable.groupByTo(destination: B, keySelector: (V) -> K) = null as B + +enum class Format { Foo, Bar } + +class Instance(val format: Format) + +fun main(x: List) { + val doesntWork = x.groupByTo( + Simple.ListSimple(EnumMap>(Format::class.java), ::LinkedList) + ) { it.format } // Internal Error occurred while analyzing this expression +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.txt new file mode 100644 index 00000000000..f4bc333f9f4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.txt @@ -0,0 +1,49 @@ +package + +public fun main(/*0*/ x: kotlin.collections.List): kotlin.Unit +public fun , /*4*/ B : Simple> kotlin.collections.Iterable.groupByTo(/*0*/ destination: B, /*1*/ keySelector: (V) -> K): B + +public final enum class Format : kotlin.Enum { + enum entry Foo + + enum entry Bar + + private constructor Format() + public final override /*1*/ /*fake_override*/ val name: kotlin.String + public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int + protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: Format): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): Format + public final /*synthesized*/ fun values(): kotlin.Array +} + +public final class Instance { + public constructor Instance(/*0*/ format: Format) + public final val format: Format + 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 Simple!> { + public constructor Simple!>(/*0*/ backingMap: kotlin.collections.(Mutable)Map!, /*1*/ innerCollectionCreator: java.util.function.Supplier!) + public final fun add(/*0*/ key: K!, /*1*/ value: V!): kotlin.Unit + 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 ListSimple : Simple!, kotlin.collections.(Mutable)List!> { + public constructor ListSimple(/*0*/ backingMap: kotlin.collections.(Mutable)Map!>!, /*1*/ innerCollectionCreator: java.util.function.Supplier!>!) + public final override /*1*/ /*fake_override*/ fun add(/*0*/ key: K!, /*1*/ value: V!): kotlin.Unit + 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/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.kt new file mode 100644 index 00000000000..29e142ba54a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.kt @@ -0,0 +1,40 @@ +// FIR_IDENTICAL + +sealed class Tree { + abstract val value: TCommon + abstract val children: Map> + + data class Inner( + override val value: TCommon, + val innerValue: TInner, + override val children: Map> + ) : Tree() + + data class Leaf( + override val value: TCommon, + val leafValue: TLeaf + ) : Tree() { + override val children: Map> get() = emptyMap() + } +} + +val tree = Tree.Inner( + "root", + Unit, + mapOf( + 1 to Tree.Leaf("1", 1), + 2 to Tree.Inner( + "2", + Unit, + mapOf( + 1 to Tree.Leaf("21", 2), + 2 to Tree.Inner( + "22", + Unit, + mapOf(1 to Tree.Leaf("221", 3)) + ), + 3 to Tree.Leaf("23", 4) + ) + ) + ) +) \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.txt b/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.txt new file mode 100644 index 00000000000..2655dbd7a0b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.txt @@ -0,0 +1,39 @@ +package + +public val tree: Tree.Inner + +public sealed class Tree { + private constructor Tree() + public abstract val children: kotlin.collections.Map> + public abstract val value: TCommon + 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 data class Inner : Tree { + public constructor Inner(/*0*/ value: TCommon, /*1*/ innerValue: TInner, /*2*/ children: kotlin.collections.Map>) + public open override /*1*/ val children: kotlin.collections.Map> + public final val innerValue: TInner + public open override /*1*/ val value: TCommon + public final operator /*synthesized*/ fun component1(): TCommon + public final operator /*synthesized*/ fun component2(): TInner + public final operator /*synthesized*/ fun component3(): kotlin.collections.Map> + public final /*synthesized*/ fun copy(/*0*/ value: TCommon = ..., /*1*/ innerValue: TInner = ..., /*2*/ children: kotlin.collections.Map> = ...): Tree.Inner + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String + } + + public final data class Leaf : Tree { + public constructor Leaf(/*0*/ value: TCommon, /*1*/ leafValue: TLeaf) + public open override /*1*/ val children: kotlin.collections.Map> + public final val leafValue: TLeaf + public open override /*1*/ val value: TCommon + public final operator /*synthesized*/ fun component1(): TCommon + public final operator /*synthesized*/ fun component2(): TLeaf + public final /*synthesized*/ fun copy(/*0*/ value: TCommon = ..., /*1*/ leafValue: TLeaf = ...): Tree.Leaf + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String + } +} diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/11.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/11.kt index 54ae074252c..436fb58d2ee 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/11.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/11.kt @@ -29,7 +29,7 @@ fun case_3(a: Any) { // TESTCASE NUMBER: 4 open class TypeToken -val case_4 = object : TypeToken<@Ann(10) String>() {} +val case_4 = object : TypeToken<@Ann(10) String>() {} // TESTCASE NUMBER: 5 fun case_5(a: Any) { diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.kt b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.kt index 05a5b0cadba..e27ee9b838b 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/annotations/type-annotations/neg/7.kt @@ -19,7 +19,7 @@ annotation class Ann */ open class TypeToken -val case_1 = object : TypeToken<@Ann(unresolved_reference) String>() {} +val case_1 = object : TypeToken<@Ann(unresolved_reference) String>() {} /* * TESTCASE NUMBER: 2 diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 0eb221f47b6..42130d9dd3d 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -3173,6 +3173,29 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/inference/recursiveFlexibleAssertions.kt"); } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AddEqualityConstraintsWithoutSubtyping extends AbstractDiagnosticsTestWithStdLib { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInAddEqualityConstraintsWithoutSubtyping() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("kt41741.kt") + public void testKt41741() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.kt"); + } + + @TestMetadata("kt42195.kt") + public void testKt42195() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.kt"); + } + } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index ee81362429a..331537666a5 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -3173,6 +3173,29 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/inference/recursiveFlexibleAssertions.kt"); } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class AddEqualityConstraintsWithoutSubtyping extends AbstractDiagnosticsTestWithStdLibUsingJavac { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInAddEqualityConstraintsWithoutSubtyping() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @TestMetadata("kt41741.kt") + public void testKt41741() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt41741.kt"); + } + + @TestMetadata("kt42195.kt") + public void testKt42195() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/inference/addEqualityConstraintsWithoutSubtyping/kt42195.kt"); + } + } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/testData/checker/MultipleBounds.kt b/idea/testData/checker/MultipleBounds.kt index 13f6b91f413..880c316c9ab 100644 --- a/idea/testData/checker/MultipleBounds.kt +++ b/idea/testData/checker/MultipleBounds.kt @@ -18,46 +18,46 @@ class Test1() where T : A, T : B, - B : T // error + B : T // error { fun test(t : T) { - T.foo() - T.bar() + T.foo() + T.bar() t.foo() t.bar() } } fun test() { - Test1<B>() - Test1<A>() + Test1<B>() + Test1<A>() Test1() } class Foo() {} -class BarFoo> +class BarFoo> -class Buzz where T : Bar<Int>, T : nioho +class Buzz where T : Bar<Int>, T : nioho -class XFoo> -class Y<T> where T : Foo, T : Bar +class XFoo> +class Y<T> where T : Foo, T : Bar fun test2(t : T) where T : A, T : B, - B : T + B : T { - T.foo() - T.bar() + T.foo() + T.bar() t.foo() t.bar() } -val t1 = test2<A>(A()) -val t2 = test2<B>(C()) +val t1 = test2<A>(A()) +val t2 = test2<B>(C()) val t3 = test2(C()) val Pair.x : Int get() = 0