diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt index 360e18df6ae..e23c8d24d53 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt @@ -154,6 +154,11 @@ class ConstraintInjector(val constraintIncorporator: ConstraintIncorporator, val ?: error("Should by type variableConstructor: $typeVariableConstructor. ${c.allTypeVariables.values}") var targetType = type + if (targetType.isError) { + c.addError(ConstrainingTypeIsError(typeVariable, targetType, position)) + return + } + if (type.contains(this::isCapturedTypeFromSubtyping)) { // TypeVariable <: type -> if TypeVariable <: subType => TypeVariable <: type if (kind == UPPER) { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt index bcbdb71844d..0f2c7ceb68e 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt @@ -92,4 +92,10 @@ class CapturedTypeFromSubtyping( val position: ConstraintPosition ) : ConstraintSystemCallDiagnostic(INAPPLICABLE) -class NotEnoughInformationForTypeParameter(val typeVariable: NewTypeVariable) : ConstraintSystemCallDiagnostic(INAPPLICABLE) \ No newline at end of file +class NotEnoughInformationForTypeParameter(val typeVariable: NewTypeVariable) : ConstraintSystemCallDiagnostic(INAPPLICABLE) + +class ConstrainingTypeIsError( + val typeVariable: NewTypeVariable, + val constraintType: UnwrappedType, + val position: IncorporationConstraintPosition +) : ConstraintSystemCallDiagnostic(INAPPLICABLE) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/UnrelatedColon.ni.txt b/compiler/testData/diagnostics/tests/cast/bare/UnrelatedColon.ni.txt index a4550a556ef..3deb20fc81f 100644 --- a/compiler/testData/diagnostics/tests/cast/bare/UnrelatedColon.ni.txt +++ b/compiler/testData/diagnostics/tests/cast/bare/UnrelatedColon.ni.txt @@ -1,6 +1,6 @@ package -public fun test(/*0*/ tr: Tr): [ERROR : G] +public fun test(/*0*/ tr: Tr): Tr public interface G { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.kt index 8ca621d279d..c090b9640c5 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unresolvedReference.kt @@ -1,4 +1,3 @@ -// !WITH_NEW_INFERENCE // See KT-6665: unresolved reference (v.bar) should not produce "unreachable code" after it fun foo(): Int { @@ -29,14 +28,14 @@ fun foo3(): Int { fun bar(): Int { val v = 1 val c = v.bar ?: 42 - return c + return c } fun bar2(): Int { val v = 1 val c = if (true) v.bar else 3 - val b = c - return b + val b = c + return b } fun bar3(): Int { @@ -45,6 +44,6 @@ fun bar3(): Int { true -> v.bar else -> 3 } - val b = c - return b + val b = c + return b } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt index eda496595bc..dd4bb974523 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethods.kt @@ -1,10 +1,9 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -// !WITH_NEW_INFERENCE // NI_EXPECTED_FILE import kotlin.reflect.KProperty var a: Int by A() -var a1 by A() +var a1 by A() var b: Int by B() diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/ForbiddenNonLocalReturnNoType.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/ForbiddenNonLocalReturnNoType.kt index 0ad96640de8..037dec7797e 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/return/ForbiddenNonLocalReturnNoType.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/ForbiddenNonLocalReturnNoType.kt @@ -1,18 +1,18 @@ // !WITH_NEW_INFERENCE fun test() { run {return} - run {} + run {} } fun test2() { run {return@test2} - run {} + run {} } fun test3() { fun test4() { run {return@test3} - run {} + run {} } } diff --git a/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.kt b/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.kt new file mode 100644 index 00000000000..26de6fec138 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.kt @@ -0,0 +1,26 @@ +// !LANGUAGE: +NewInference + +// FILE: Sam.java + +public interface Sam { + Sam.Result compute(); + + public static class Result { + public static Sam.Result create(V value) {} + } +} + +// FILE: Foo.java + +public class Foo { + public static void foo(Sam var1) { + } +} + +// FILE: test.kt + +fun test(e: ErrorType) { + Foo.foo { + Sam.Result.create(e) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.txt b/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.txt new file mode 100644 index 00000000000..c6adb9614d4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.txt @@ -0,0 +1,30 @@ +package + +public fun test(/*0*/ e: [ERROR : ErrorType]): kotlin.Unit + +public open class Foo { + public constructor Foo() + 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 + + // Static members + public open fun foo(/*0*/ var1: Sam!): kotlin.Unit +} + +public interface Sam { + public abstract fun compute(): Sam.Result! + 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 Result { + public constructor Result() + 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 + + // Static members + public open fun create(/*0*/ value: V!): Sam.Result! + } +} diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.kt index 7dfa9c04a2c..1d553689322 100644 --- a/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.kt +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.kt @@ -57,7 +57,7 @@ fun test3(z: Z) { //'in' operation fun test4(collection: Collection>) { id(newA() in collection) - id(newA() in collection) + id(newA() in collection) } //boolean operations diff --git a/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/selfCall.kt b/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/selfCall.kt index 032505c6c2f..029c77abb9d 100644 --- a/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/selfCall.kt +++ b/compiler/testData/diagnostics/tests/inference/recursiveLocalFuns/selfCall.kt @@ -3,7 +3,7 @@ fun foo() { fun bar1() = bar1() fun bar2() = 1 + bar2() - fun bar3() = id(bar3()) + fun bar3() = id(bar3()) } fun id(x: T) = x diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/elvis.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/elvis.kt index c8b19ee5d91..3a0ed4efc32 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/elvis.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/elvis.kt @@ -1,5 +1,4 @@ // !DIAGNOSTICS: -UNUSED_VARIABLE -SENSELESS_COMPARISON, -UNUSED_PARAMETER -// !WITH_NEW_INFERENCE // FILE: J.java @@ -62,7 +61,7 @@ fun test() { takeNotNull(J.getNAny() ?: J()) val x = unresolved ?: null - val y = unresolved.foo ?: return + val y = unresolved.foo ?: return } fun takeNotNull(s: J) {} diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/recursiveGetter.kt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/recursiveGetter.kt index fdaa7e1e5c0..632b8a87ad9 100644 --- a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/recursiveGetter.kt +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/recursiveGetter.kt @@ -10,7 +10,7 @@ class A { val a get() = b val b get() = a - val z1 get() = id(z1) + val z1 get() = id(z1) val z2 get() = l(z2) val u get() = field diff --git a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/recursiveGetter.ni.txt b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/recursiveGetter.ni.txt index 1efd38b174b..ed4126242a5 100644 --- a/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/recursiveGetter.ni.txt +++ b/compiler/testData/diagnostics/tests/properties/inferenceFromGetters/recursiveGetter.ni.txt @@ -10,8 +10,8 @@ public final class A { public final val b: [ERROR : Error function type] public final val u: [ERROR : Error function type] public final val y: [ERROR : Error function type] - public final val z1: [ERROR : Error type for ParseError-argument VALUE_ARGUMENT] - public final val z2: kotlin.collections.List<[ERROR : Error type for ParseError-argument VALUE_ARGUMENT]> + public final val z1: kotlin.Nothing + public final val z2: kotlin.collections.List 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 f4f3126903b..c389787247c 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -9565,6 +9565,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/inference/constraints/equalityConstraintOnNullableType.kt"); } + @TestMetadata("errorUpperBoundConstraint.kt") + public void testErrorUpperBoundConstraint() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.kt"); + } + @TestMetadata("ignoreConstraintFromImplicitInNothing.kt") public void testIgnoreConstraintFromImplicitInNothing() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/constraints/ignoreConstraintFromImplicitInNothing.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index c073d06c620..171d092d4be 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -9565,6 +9565,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/constraints/equalityConstraintOnNullableType.kt"); } + @TestMetadata("errorUpperBoundConstraint.kt") + public void testErrorUpperBoundConstraint() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.kt"); + } + @TestMetadata("ignoreConstraintFromImplicitInNothing.kt") public void testIgnoreConstraintFromImplicitInNothing() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/constraints/ignoreConstraintFromImplicitInNothing.kt");