From fbf68a5bccece37914f573654c5c9dc8e514e157 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Fri, 22 Sep 2023 11:25:51 +0200 Subject: [PATCH] [FIR] Narrow down range of NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER This uses the same approach as INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION where we use a visitor to find a call to a symbol that contains the type variable in question. #KT-56140 Fixed --- ...bleReferenceDependingOnInferredReceiver.kt | 4 +-- .../coneDiagnosticToFirDiagnostic.kt | 11 ++++--- .../callableReference/kt34314_lambda.fir.kt | 7 ----- .../tests/callableReference/kt34314_lambda.kt | 1 + ...eferenceDependingOnInferredReceiver.fir.kt | 4 +-- .../differentDelegatedExpressions.fir.kt | 8 ++--- .../noTypeParamsInReturnType.fir.kt | 2 +- .../specialCallsWithCallableReferences.fir.kt | 18 +++++------ ...erencesDontCareTypeInBlockExression.fir.kt | 4 +-- ...allsWithCallableReferencesErrorType.fir.kt | 2 +- ...ableReferencesErrorTypeUnrestricted.fir.kt | 2 +- ...sWithCallableReferencesUnrestricted.fir.kt | 18 +++++------ ...ferableParameterOfAnonymousFunction.fir.kt | 4 +-- ...finitelyNotNullTypeInReturnPosition.fir.kt | 4 +-- .../errorUpperBoundConstraint.fir.kt | 4 +-- .../tests/inference/constraints/kt8879.fir.kt | 12 -------- .../tests/inference/constraints/kt8879.kt | 1 + .../inference/expectedTypeFromCast.fir.kt | 20 ------------- .../tests/inference/expectedTypeFromCast.kt | 1 + .../inference/functionPlaceholderError.fir.kt | 16 ---------- .../inference/functionPlaceholderError.kt | 1 + .../nestedCalls/binaryExpressions.fir.kt | 8 ++--- ...implicitInferenceTToFlexibleNothing.fir.kt | 10 ------- .../implicitInferenceTToFlexibleNothing.kt | 1 + .../notEnoughInformationAndNothing.fir.kt | 12 ++++---- ...nformationFromNullabilityConstraint.fir.kt | 4 +-- .../possibleCycleOnConstraints.fir.kt | 13 -------- .../inference/possibleCycleOnConstraints.kt | 1 + .../inference/regressions/kt33629.fir.kt | 20 ------------- .../tests/inference/regressions/kt33629.kt | 1 + .../inference/regressions/kt36342.fir.kt | 10 +++---- .../inference/regressions/kt36342_2.fir.kt | 4 +-- .../tests/inference/regressions/kt948.fir.kt | 2 +- ...InformationErrorsOnBlockExpressions.fir.kt | 8 ++--- .../specialCallsWithCallableReferences.fir.kt | 30 +++++++++---------- ...gVariableByMaterializeAndUpperBound.fir.kt | 14 --------- ...rringVariableByMaterializeAndUpperBound.kt | 1 + ...tResultSubstitutorForErrorCandidate.fir.kt | 2 +- .../tests/regressions/kt24488.fir.kt | 14 --------- .../diagnostics/tests/regressions/kt24488.kt | 1 + .../buildListToUpperBoundInLazy.fir.kt | 8 ++--- ...uildListToUpperBoundInLazyForbidden.fir.kt | 8 ++--- .../diagnostics/notLinked/dfa/neg/1.fir.kt | 6 ++-- .../diagnostics/notLinked/dfa/pos/6.fir.kt | 6 ++-- 44 files changed, 105 insertions(+), 223 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/constraints/kt8879.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/expectedTypeFromCast.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/functionPlaceholderError.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/nothingType/implicitInferenceTToFlexibleNothing.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt33629.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/regressions/kt24488.fir.kt diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/fromBasicDiagnosticTests/chooseCallableReferenceDependingOnInferredReceiver.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/fromBasicDiagnosticTests/chooseCallableReferenceDependingOnInferredReceiver.kt index 067519af20e..a3a42e6696c 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/fromBasicDiagnosticTests/chooseCallableReferenceDependingOnInferredReceiver.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/fromBasicDiagnosticTests/chooseCallableReferenceDependingOnInferredReceiver.kt @@ -14,8 +14,8 @@ class B { fun bar(f: (T) -> Unit): T = TODO() fun test() { - myWith(A()) { - val t1 = bar(::foo) + myWith(A()) { + val t1 = bar(::foo) val t2 = bar(::baz) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 95ee0ae05f5..0ae30bc0395 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -465,7 +465,7 @@ private fun ConstraintSystemError.toDiagnostic( } FirErrors.NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER.createOn( - source, + candidate.sourceOfCallToSymbolWith(this.typeVariable as ConeTypeVariable) ?: source, typeVariableName, ) } @@ -479,7 +479,7 @@ private fun ConstraintSystemError.toDiagnostic( is InferredEmptyIntersection -> { val typeVariable = typeVariable as ConeTypeVariable - val narrowedSource = findInferredEmptyIntersectionNarrowedSource(typeVariable, candidate) + val narrowedSource = candidate.sourceOfCallToSymbolWith(typeVariable) @Suppress("UNCHECKED_CAST") reportInferredIntoEmptyIntersection( @@ -503,15 +503,14 @@ private fun ConstraintSystemError.toDiagnostic( } } -private fun findInferredEmptyIntersectionNarrowedSource( +private fun AbstractCandidate.sourceOfCallToSymbolWith( typeVariable: ConeTypeVariable, - candidate: AbstractCandidate, ): KtSourceElement? { if (typeVariable !is ConeTypeParameterBasedTypeVariable) return null var narrowedSource: KtSourceElement? = null - candidate.callInfo.callSite.accept(object : FirVisitorVoid() { + callInfo.callSite.accept(object : FirVisitorVoid() { override fun visitElement(element: FirElement) { if (narrowedSource != null) return @@ -537,7 +536,7 @@ private fun reportInferredIntoEmptyIntersection( causingTypes: Collection, kind: EmptyIntersectionTypeKind, isError: Boolean -): KtDiagnostic? { +): KtDiagnostic { val typeVariableText = (typeVariable.typeConstructor.originalTypeParameter as? ConeTypeParameterLookupTag)?.name?.asString() ?: typeVariable.toString() diff --git a/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.fir.kt b/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.fir.kt deleted file mode 100644 index d619986d107..00000000000 --- a/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.fir.kt +++ /dev/null @@ -1,7 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE - -fun materialize(): T = TODO() - -fun main() { - val x = run { materialize() } -} diff --git a/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.kt b/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.kt index b5756897634..c90774d5dd2 100644 --- a/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.kt +++ b/compiler/testData/diagnostics/tests/callableReference/kt34314_lambda.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE fun materialize(): T = TODO() diff --git a/compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.fir.kt b/compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.fir.kt index 59021568d8c..7dc38927dad 100644 --- a/compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/resolve/chooseCallableReferenceDependingOnInferredReceiver.fir.kt @@ -16,8 +16,8 @@ class B { fun bar(f: (T) -> Unit): T = TODO() fun test() { - myWith(A()) { - val t1 = bar(::foo) + myWith(A()) { + val t1 = bar(::foo) t1 val t2 = bar(::baz) diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt index 0236a86a45b..c1b55fc4422 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/differentDelegatedExpressions.fir.kt @@ -9,10 +9,10 @@ class A(outer: Outer) { var g: String by outer.getContainer().getMyProperty() - var b: String by foo(getMyProperty()) - var r: String by foo(outer.getContainer().getMyProperty()) - var e: String by + foo(getMyProperty()) - var f: String by foo(getMyProperty()) - 1 + var b: String by foo(getMyProperty()) + var r: String by foo(outer.getContainer().getMyProperty()) + var e: String by + foo(getMyProperty()) + var f: String by foo(getMyProperty()) - 1 } fun foo(a: Any?) = MyProperty() diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/noTypeParamsInReturnType.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/noTypeParamsInReturnType.fir.kt index aebf4a51dbc..9137b2ee1be 100644 --- a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/noTypeParamsInReturnType.fir.kt +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/noTypeParamsInReturnType.fir.kt @@ -5,5 +5,5 @@ fun foo(map: Map) : R = throw Exception() fun getMap() : Map = throw Exception() fun bar123() { - foo(getMap( + foo(getMap( } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.fir.kt index eae164a7465..866cbc0a23f 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.fir.kt @@ -80,7 +80,7 @@ fun poll05(): Flow { fun poll06(): Flow { return flow { - val inv = select(foo7(), ::Foo7) + val inv = select(foo7(), ::Foo7) inv } } @@ -136,7 +136,7 @@ fun poll16(flag: Boolean): Flow { fun poll17(flag: Boolean): Flow { return flow { - val inv = if (flag) { foo7() } else { ::Foo7 } + val inv = if (flag) { foo7() } else { ::Foo7 } inv } } @@ -185,7 +185,7 @@ fun poll25(flag: Boolean): Flow { fun poll26(flag: Boolean): Flow { return flow { - val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } + val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } inv } } @@ -234,7 +234,7 @@ fun poll35(flag: Boolean): Flow { fun poll36(flag: Boolean): Flow { return flow { - val inv = when (flag) { true -> ::Foo7 false -> foo7() } + val inv = when (flag) { true -> ::Foo7 false -> foo7() } inv } } @@ -332,7 +332,7 @@ fun poll55(): Flow { fun poll56(): Flow { return flow { - val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } + val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } inv } } @@ -430,7 +430,7 @@ fun poll75(): Flow { fun poll76(): Flow { return flow { - val inv = ::Foo7!! + val inv = ::Foo7!! inv } } @@ -479,21 +479,21 @@ fun poll85(): Flow { fun poll86(): Flow { return flow { - val inv = ::Foo7 in setOf(::Foo7) + val inv = ::Foo7 in setOf(::Foo7) inv } } fun poll87(): Flow { return flow { - val inv = ::Foo7 in setOf(foo7()) + val inv = ::Foo7 in setOf(foo7()) inv } } fun poll88(): Flow { return flow { - val inv = foo7() in setOf(::Foo7) + val inv = foo7() in setOf(::Foo7) inv } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontCareTypeInBlockExression.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontCareTypeInBlockExression.fir.kt index 799848a99ba..7f9880ad574 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontCareTypeInBlockExression.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesDontCareTypeInBlockExression.fir.kt @@ -85,7 +85,7 @@ fun poll16(flag: Boolean): Flow { fun poll17(flag: Boolean): Flow { return flow { - val inv = if (flag) { foo7() } else { ::Foo7 } + val inv = if (flag) { foo7() } else { ::Foo7 } inv } } @@ -183,7 +183,7 @@ fun poll55(): Flow { fun poll56(): Flow { return flow { - val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } + val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } inv } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorType.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorType.fir.kt index f55b0663f40..354f2a45e91 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorType.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorType.fir.kt @@ -79,7 +79,7 @@ fun poll75(): Flow { fun poll76(): Flow { return flow { - val inv = ::Foo7!! + val inv = ::Foo7!! inv } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorTypeUnrestricted.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorTypeUnrestricted.fir.kt index b44791c73f7..881ac3e7314 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorTypeUnrestricted.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesErrorTypeUnrestricted.fir.kt @@ -80,7 +80,7 @@ fun poll75(): Flow { fun poll76(): Flow { return flow { - val inv = ::Foo7!! + val inv = ::Foo7!! inv } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesUnrestricted.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesUnrestricted.fir.kt index ff20ee35762..adc7e3b777b 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesUnrestricted.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferencesUnrestricted.fir.kt @@ -82,7 +82,7 @@ fun poll05(): Flow { fun poll06(): Flow { return flow { - val inv = select(foo7(), ::Foo7) + val inv = select(foo7(), ::Foo7) inv } } @@ -138,7 +138,7 @@ fun poll16(flag: Boolean): Flow { fun poll17(flag: Boolean): Flow { return flow { - val inv = if (flag) { foo7() } else { ::Foo7 } + val inv = if (flag) { foo7() } else { ::Foo7 } inv } } @@ -187,7 +187,7 @@ fun poll25(flag: Boolean): Flow { fun poll26(flag: Boolean): Flow { return flow { - val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } + val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } inv } } @@ -236,7 +236,7 @@ fun poll35(flag: Boolean): Flow { fun poll36(flag: Boolean): Flow { return flow { - val inv = when (flag) { true -> ::Foo7 false -> foo7() } + val inv = when (flag) { true -> ::Foo7 false -> foo7() } inv } } @@ -334,7 +334,7 @@ fun poll55(): Flow { fun poll56(): Flow { return flow { - val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } + val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } inv } } @@ -432,7 +432,7 @@ fun poll75(): Flow { fun poll76(): Flow { return flow { - val inv = ::Foo7!! + val inv = ::Foo7!! inv } } @@ -481,21 +481,21 @@ fun poll85(): Flow { fun poll86(): Flow { return flow { - val inv = ::Foo7 in setOf(::Foo7) + val inv = ::Foo7 in setOf(::Foo7) inv } } fun poll87(): Flow { return flow { - val inv = ::Foo7 in setOf(foo7()) + val inv = ::Foo7 in setOf(foo7()) inv } } fun poll88(): Flow { return flow { - val inv = foo7() in setOf(::Foo7) + val inv = foo7() in setOf(::Foo7) inv } } diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.fir.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.fir.kt index ec8755eebde..a06ef229d47 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/notInferableParameterOfAnonymousFunction.fir.kt @@ -5,9 +5,9 @@ fun id(x: K) = x fun main() { val x1 = select(id { x, y -> }, { x: Int, y -> }) - val x2 = 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/constraints/definitelyNotNullTypeInReturnPosition.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/definitelyNotNullTypeInReturnPosition.fir.kt index 7c03187069e..a2e991c8e37 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/definitelyNotNullTypeInReturnPosition.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/constraints/definitelyNotNullTypeInReturnPosition.fir.kt @@ -262,8 +262,8 @@ class Main(x: L?, y: L) { val x471 = foo47(y) fun takeLambda(block: () -> R): R = materialize() - val x480 = takeLambda { foo48 { x } } - val x481 = takeLambda { foo48 { y } } + val x480 = takeLambda { foo48 { x } } + val x481 = takeLambda { foo48 { y } } val x482 = takeLambda { foo48 { null } } } diff --git a/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.fir.kt index e0d4c6f5d1a..ad7e050c715 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.fir.kt @@ -19,7 +19,7 @@ public class Foo { // FILE: test.kt fun test(e: ErrorType) { - Foo.foo { - Sam.Result.create(e) + Foo.foo { + Sam.Result.create(e) } } diff --git a/compiler/testData/diagnostics/tests/inference/constraints/kt8879.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/kt8879.fir.kt deleted file mode 100644 index 7705b37e0a4..00000000000 --- a/compiler/testData/diagnostics/tests/inference/constraints/kt8879.fir.kt +++ /dev/null @@ -1,12 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -interface Inv -interface Inv2 - -fun > foo(klass: Inv): String? = null - -fun bar(): Inv = null!! - -fun test() { - foo(bar()) -} diff --git a/compiler/testData/diagnostics/tests/inference/constraints/kt8879.kt b/compiler/testData/diagnostics/tests/inference/constraints/kt8879.kt index caa6880dc8e..1bc89af7640 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/kt8879.kt +++ b/compiler/testData/diagnostics/tests/inference/constraints/kt8879.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER interface Inv diff --git a/compiler/testData/diagnostics/tests/inference/expectedTypeFromCast.fir.kt b/compiler/testData/diagnostics/tests/inference/expectedTypeFromCast.fir.kt deleted file mode 100644 index ea67e02b73d..00000000000 --- a/compiler/testData/diagnostics/tests/inference/expectedTypeFromCast.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -// !LANGUAGE: +ExpectedTypeFromCast - -fun foo(): T = TODO() - -fun id(value: V) = value - -val asString = foo() as String - -val viaId = id(foo()) as String - -val insideId = id(foo() as String) - -val asList = foo() as List - -val asStarList = foo() as List<*> - -val safeAs = foo() as? String - -val fromIs = foo() is String -val fromNoIs = foo() !is String diff --git a/compiler/testData/diagnostics/tests/inference/expectedTypeFromCast.kt b/compiler/testData/diagnostics/tests/inference/expectedTypeFromCast.kt index 402b7d650f8..a3a8d971075 100644 --- a/compiler/testData/diagnostics/tests/inference/expectedTypeFromCast.kt +++ b/compiler/testData/diagnostics/tests/inference/expectedTypeFromCast.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +ExpectedTypeFromCast fun foo(): T = TODO() diff --git a/compiler/testData/diagnostics/tests/inference/functionPlaceholderError.fir.kt b/compiler/testData/diagnostics/tests/inference/functionPlaceholderError.fir.kt deleted file mode 100644 index d7c2a15c718..00000000000 --- a/compiler/testData/diagnostics/tests/inference/functionPlaceholderError.fir.kt +++ /dev/null @@ -1,16 +0,0 @@ -// !CHECK_TYPE - -package a - -import checkSubtype - -fun emptyList(): List = throw Exception() - -fun foo(f: T.() -> Unit, l: List): T = throw Exception("$f$l") - -fun test() { - val q = foo(fun Int.() {}, emptyList()) //type inference no information for parameter error - checkSubtype(q) - - foo({}, emptyList()) -} diff --git a/compiler/testData/diagnostics/tests/inference/functionPlaceholderError.kt b/compiler/testData/diagnostics/tests/inference/functionPlaceholderError.kt index 338c1397a81..a01587105fb 100644 --- a/compiler/testData/diagnostics/tests/inference/functionPlaceholderError.kt +++ b/compiler/testData/diagnostics/tests/inference/functionPlaceholderError.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !CHECK_TYPE package a diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.fir.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.fir.kt index bab21744e83..35490efb292 100644 --- a/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/binaryExpressions.fir.kt @@ -13,7 +13,7 @@ fun id(t: T): T = t infix fun Z.foo(a: A): A = a fun test(z: Z) { - z foo newA() + z foo newA() val a: A = id(z foo newA()) val b: A = id(z.foo(newA())) use(a, b) @@ -23,7 +23,7 @@ fun test(z: Z) { operator fun Z.plus(a: A): A = a fun test1(z: Z) { - id(z + newA()) + id(z + newA()) val a: A = z + newA() val b: A = z.plus(newA()) val c: A = id(z + newA()) @@ -35,7 +35,7 @@ fun test1(z: Z) { operator fun Z.compareTo(a: A): Int { use(a); return 1 } fun test2(z: Z) { - val a: Boolean = id(z < newA()) + val a: Boolean = id(z < newA()) val b: Boolean = id(z < newA()) use(a, b) } @@ -55,7 +55,7 @@ fun test3(z: Z) { //'in' operation fun test4(collection: Collection>) { - id(newA() in collection) + id(newA() in collection) id(newA() in collection) } diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/implicitInferenceTToFlexibleNothing.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/implicitInferenceTToFlexibleNothing.fir.kt deleted file mode 100644 index 2197a63a8b8..00000000000 --- a/compiler/testData/diagnostics/tests/inference/nothingType/implicitInferenceTToFlexibleNothing.fir.kt +++ /dev/null @@ -1,10 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNCHECKED_CAST -UNUSED_PARAMETER -// SKIP_TXT - -import java.util.* - -fun foo (f: () -> List): T = null as T - -fun main() { - val x = foo { Collections.emptyList() } -} diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/implicitInferenceTToFlexibleNothing.kt b/compiler/testData/diagnostics/tests/inference/nothingType/implicitInferenceTToFlexibleNothing.kt index d296739f3cc..e7b6575dc1b 100644 --- a/compiler/testData/diagnostics/tests/inference/nothingType/implicitInferenceTToFlexibleNothing.kt +++ b/compiler/testData/diagnostics/tests/inference/nothingType/implicitInferenceTToFlexibleNothing.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_VARIABLE -UNCHECKED_CAST -UNUSED_PARAMETER // SKIP_TXT diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationAndNothing.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationAndNothing.fir.kt index 2c1d9e280bb..43b5c4161b2 100644 --- a/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationAndNothing.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationAndNothing.fir.kt @@ -16,8 +16,8 @@ fun test1(b: Boolean?) { } fun test2() { - select( - materialize() + select( + materialize() ) select(materialize(), materialize()) select(materialize(), null, Inv()) @@ -25,12 +25,12 @@ fun test2() { materialize(), null ) - select( - materialize(), + select( + materialize(), materialize() ) - select( - materialize(), + select( + materialize(), materialize(), null ) diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.fir.kt index bfbaeacf144..abc2c0f260e 100644 --- a/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/nothingType/notEnoughInformationFromNullabilityConstraint.fir.kt @@ -5,8 +5,8 @@ fun id(arg: I): I = arg fun select(vararg args: S): S = TODO() fun test() { - id( - make() + id( + make() ) select(make(), null) diff --git a/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.fir.kt b/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.fir.kt deleted file mode 100644 index 9157a35b3f9..00000000000 --- a/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.fir.kt +++ /dev/null @@ -1,13 +0,0 @@ -package a - -import java.util.* - -fun g (f: () -> List) : T {} - -fun test() { - //here possibly can be a cycle on constraints - val x = g { Collections.emptyList() } - - val y = g { Collections.emptyList() } - val z : List = g { Collections.emptyList() } -} diff --git a/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.kt b/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.kt index a1805f4560a..2420a453474 100644 --- a/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.kt +++ b/compiler/testData/diagnostics/tests/inference/possibleCycleOnConstraints.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL package a import java.util.* diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt33629.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt33629.fir.kt deleted file mode 100644 index 1be4ad4d550..00000000000 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt33629.fir.kt +++ /dev/null @@ -1,20 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER - -fun emptyList(): List = TODO() - -data class IntervalTree( - val left: IntervalTree?, - val right: IntervalTree?, - val intervals: List, - val median: Float -) - -class Interval - -fun buildTree(segments: List): IntervalTree? = TODO() -fun acquireIntervals(): List = TODO() - -fun main() { - buildTree(acquireIntervals()) - ?: emptyList() -} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt33629.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt33629.kt index a719a6f09d2..8c0628a7f8b 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt33629.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt33629.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER fun emptyList(): List = TODO() diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt36342.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt36342.fir.kt index 27b6afb8c7f..53bc861e9cb 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt36342.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt36342.fir.kt @@ -6,19 +6,19 @@ fun id(arg: K): K = arg fun test() { id(unresolved)!! unresolved!!!! - try { - id(unresolved) + try { + id(unresolved) } catch (e: Exception) { id(unresolved) } - if (true) - id(unresolved) + if (true) + id(unresolved) else id(unresolved) when { true -> id(unresolved) } - id(unresolved) ?: id(unresolved) + id(unresolved) ?: id(unresolved) } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt36342_2.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt36342_2.fir.kt index acc169754a2..2d63f5c4196 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt36342_2.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt36342_2.fir.kt @@ -3,11 +3,11 @@ fun id(arg: K): K = arg fun materialize(): M = TODO() fun test(b: Boolean) { - id(if (b) { + id(if (b) { id(unresolved) } else { id( - materialize() + materialize() ) }) } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt948.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt948.fir.kt index 9f2f92227a3..23c56a21c89 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt948.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt948.fir.kt @@ -12,7 +12,7 @@ fun emptyList() : List? = ArrayList() fun foo() { // type arguments shouldn't be required val l : List = emptyList()!! - val l1 = emptyList()!! + val l1 = emptyList()!! checkSubtype>(emptyList()!!) checkSubtype?>(emptyList()) diff --git a/compiler/testData/diagnostics/tests/inference/reportNotEnoughTypeInformationErrorsOnBlockExpressions.fir.kt b/compiler/testData/diagnostics/tests/inference/reportNotEnoughTypeInformationErrorsOnBlockExpressions.fir.kt index 2eebfb6f659..a573fded5ef 100644 --- a/compiler/testData/diagnostics/tests/inference/reportNotEnoughTypeInformationErrorsOnBlockExpressions.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/reportNotEnoughTypeInformationErrorsOnBlockExpressions.fir.kt @@ -9,21 +9,21 @@ class Foo7 fun foo7() = null as Foo7 fun poll17(flag: Boolean): Any? { - val inv = if (flag) { foo7() } else { ::Foo7 } + val inv = if (flag) { foo7() } else { ::Foo7 } return inv } fun poll26(flag: Boolean): Any? { - val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } + val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } return inv } fun poll36(flag: Boolean): Any? { - val inv = when (flag) { true -> ::Foo7 false -> foo7() } + val inv = when (flag) { true -> ::Foo7 false -> foo7() } return inv } fun poll56(): Any? { - val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } + val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } return inv } diff --git a/compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.fir.kt b/compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.fir.kt index abfbd38167f..8cb33e95476 100644 --- a/compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/specialCallsWithCallableReferences.fir.kt @@ -44,7 +44,7 @@ fun poll13(flag: Boolean) { } fun poll14(flag: Boolean) { - val inv = if (flag) { ::bar4 } else { ::foo4 } + val inv = if (flag) { ::bar4 } else { ::foo4 } inv() } @@ -59,7 +59,7 @@ fun poll16(flag: Boolean) { } fun poll17(flag: Boolean) { - val inv = if (flag) { foo7() } else { ::Foo7 } + val inv = if (flag) { foo7() } else { ::Foo7 } inv } @@ -79,7 +79,7 @@ fun poll22(flag: Boolean) { } fun poll23(flag: Boolean) { - val inv = when (flag) { true -> ::bar4 else -> ::foo4 } + val inv = when (flag) { true -> ::bar4 else -> ::foo4 } inv() } @@ -94,7 +94,7 @@ fun poll25(flag: Boolean) { } fun poll26(flag: Boolean) { - val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } + val inv = when (flag) { true -> ::Foo7 false -> foo7() else -> ::Foo7 } inv } @@ -114,7 +114,7 @@ fun poll32(flag: Boolean) { } fun poll33(flag: Boolean) { - val inv = when (flag) { true -> ::bar4 false -> ::foo4 } + val inv = when (flag) { true -> ::bar4 false -> ::foo4 } inv() } @@ -129,7 +129,7 @@ fun poll35(flag: Boolean) { } fun poll36(flag: Boolean) { - val inv = when (flag) { true -> ::Foo7 false -> foo7() } + val inv = when (flag) { true -> ::Foo7 false -> foo7() } inv } @@ -149,7 +149,7 @@ fun poll42() { } fun poll43() { - val inv = try { ::bar4 } finally { ::foo4 } + val inv = try { ::bar4 } finally { ::foo4 } inv() } @@ -184,7 +184,7 @@ fun poll52() { } fun poll53() { - val inv = try { ::bar4 } catch (e: Exception) { ::foo4 } finally { ::foo4 } + val inv = try { ::bar4 } catch (e: Exception) { ::foo4 } finally { ::foo4 } inv() } @@ -199,7 +199,7 @@ fun poll55() { } fun poll56() { - val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } + val inv = try { ::Foo7 } catch (e: Exception) { foo7() } finally { foo7() } inv } @@ -254,7 +254,7 @@ fun poll72() { } fun poll73() { - val inv = ::bar4!! + val inv = ::bar4!! inv } @@ -269,7 +269,7 @@ fun poll75() { } fun poll76() { - val inv = ::Foo7!! + val inv = ::Foo7!! inv } @@ -289,7 +289,7 @@ fun poll82() { } fun poll83() { - val inv = ::bar4 in setOf(::foo4) + val inv = ::bar4 in setOf(::foo4) inv } @@ -304,16 +304,16 @@ fun poll85() { } fun poll86() { - val inv = ::Foo7 in setOf(::Foo7) + val inv = ::Foo7 in setOf(::Foo7) inv } fun poll87() { - val inv = ::Foo7 in setOf(foo7()) + val inv = ::Foo7 in setOf(foo7()) inv } fun poll88() { - val inv = foo7() in setOf(::Foo7) + val inv = foo7() in setOf(::Foo7) inv } diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.fir.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.fir.kt deleted file mode 100644 index 17d46032df7..00000000000 --- a/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.fir.kt +++ /dev/null @@ -1,14 +0,0 @@ -// !DIAGNOSTICS: -CAST_NEVER_SUCCEEDS - -interface I - -interface Inv

-interface Out - -class Bar(val x: Inv>) - -fun materializeFoo(): Inv = null as Inv - -fun main() { - Bar(materializeFoo()) -} diff --git a/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.kt b/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.kt index 7bbe9a58142..1dd4b46eb30 100644 --- a/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.kt +++ b/compiler/testData/diagnostics/tests/inference/upperBounds/inferringVariableByMaterializeAndUpperBound.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -CAST_NEVER_SUCCEEDS interface I diff --git a/compiler/testData/diagnostics/tests/regressions/correctResultSubstitutorForErrorCandidate.fir.kt b/compiler/testData/diagnostics/tests/regressions/correctResultSubstitutorForErrorCandidate.fir.kt index 24ae58e45d9..f16f9393668 100644 --- a/compiler/testData/diagnostics/tests/regressions/correctResultSubstitutorForErrorCandidate.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/correctResultSubstitutorForErrorCandidate.fir.kt @@ -1,7 +1,7 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER fun test(a: Int, b: Boolean) { - bar(a.foo(b)) + bar(a.foo(b)) } fun T.foo(l: (T) -> R): R = TODO() diff --git a/compiler/testData/diagnostics/tests/regressions/kt24488.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt24488.fir.kt deleted file mode 100644 index 8d447dedcc0..00000000000 --- a/compiler/testData/diagnostics/tests/regressions/kt24488.fir.kt +++ /dev/null @@ -1,14 +0,0 @@ -// SKIP_TXT - -class Bar { - val a: Array? = null -} - -fun foo(bar: Bar) = bar.a?.asIterable() ?: emptyArray() - -fun Array.asIterable(): Iterable = TODO() - -fun testFrontend() { - val bar = Bar() - foo(bar) -} diff --git a/compiler/testData/diagnostics/tests/regressions/kt24488.kt b/compiler/testData/diagnostics/tests/regressions/kt24488.kt index 4755c64c698..c0d3fb9fd6d 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt24488.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt24488.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // SKIP_TXT class Bar { diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/buildListToUpperBoundInLazy.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/buildListToUpperBoundInLazy.fir.kt index 236d6924d5c..8c7e67e0b8b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/builderInference/buildListToUpperBoundInLazy.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/buildListToUpperBoundInLazy.fir.kt @@ -28,11 +28,11 @@ internal class TowerDataElementsForName2() { } internal class TowerDataElementsForName3() { - val reversedFilteredLocalScopes by lazy(LazyThreadSafetyMode.NONE) { + val reversedFilteredLocalScopes by lazy(LazyThreadSafetyMode.NONE) { @OptIn(ExperimentalStdlibApi::class) - buildList l1@ { + buildList l1@ { for (i in lastIndex downTo 0) { - val reversedFilteredLocalScopes by lazy(LazyThreadSafetyMode.NONE) { + val reversedFilteredLocalScopes by lazy(LazyThreadSafetyMode.NONE) { @OptIn(ExperimentalStdlibApi::class) buildList { for (i in lastIndex downTo 0) { @@ -40,7 +40,7 @@ internal class TowerDataElementsForName3() { this@l1.add("") } } - } + } } } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/buildListToUpperBoundInLazyForbidden.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/buildListToUpperBoundInLazyForbidden.fir.kt index f027088ea41..19c1ce18113 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/builderInference/buildListToUpperBoundInLazyForbidden.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/buildListToUpperBoundInLazyForbidden.fir.kt @@ -28,11 +28,11 @@ internal class TowerDataElementsForName2() { } internal class TowerDataElementsForName3() { - val reversedFilteredLocalScopes by lazy(LazyThreadSafetyMode.NONE) { + val reversedFilteredLocalScopes by lazy(LazyThreadSafetyMode.NONE) { @OptIn(ExperimentalStdlibApi::class) - buildList l1@ { + buildList l1@ { for (i in lastIndex downTo 0) { - val reversedFilteredLocalScopes by lazy(LazyThreadSafetyMode.NONE) { + val reversedFilteredLocalScopes by lazy(LazyThreadSafetyMode.NONE) { @OptIn(ExperimentalStdlibApi::class) buildList { for (i in lastIndex downTo 0) { @@ -40,7 +40,7 @@ internal class TowerDataElementsForName3() { this@l1.add("") } } - } + } } } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt index 6bae42d39cf..500b41f9a86 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt @@ -271,10 +271,10 @@ fun case_16() { } // TESTCASE NUMBER: 17 -val case_17 = if (nullableIntProperty == null == true == false) 0 else { +val case_17 = if (nullableIntProperty == null == true == false) 0 else { nullableIntProperty - nullableIntProperty.java -} + nullableIntProperty.java +} //TESTCASE NUMBER: 18 fun case_18(a: DeepObject.A.B.C.D.E.F.G.J?) { diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.fir.kt index fbf99b6926e..ff3ddef6b1f 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.fir.kt @@ -741,11 +741,11 @@ fun case_37(x: Nothing?, y: Nothing?) { fun case_38() { val z = null - if (Object.prop_2 != z) + if (Object.prop_2 != z) else { Object.prop_2 - Object.prop_2.java - } + Object.prop_2.java + } } // TESTCASE NUMBER: 39