From c6f52893fba3aeb1a11591dbd3541c06d74b5d93 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Thu, 17 Mar 2022 16:34:19 +0300 Subject: [PATCH] [FIR] Fix inconsistent RETURN_TYPE_MISMATCH and TYPE_MISMATCH reporting on functions and properties ^KT-51203 Fixed --- .../fir/generator/HLDiagnosticConverter.kt | 4 ++-- .../diagnostics/KtFirDataClassConverters.kt | 1 + .../returnTypeMismatchOnOverride.kt | 2 +- .../invoke/threeReceiversCorrect.kt | 2 +- .../RedundantVisibilityModifierChecker.kt | 2 +- .../basic.kt | 4 ++-- .../resolveWithStdlib/problems/lightMember.kt | 4 ++-- .../diagnostics/FirDiagnosticsList.kt | 4 ++-- .../fir/analysis/diagnostics/FirErrors.kt | 4 ++-- .../FirFunctionReturnTypeMismatchChecker.kt | 19 ++++++++++++++----- ...ControlFlowStatementsResolveTransformer.kt | 2 +- .../strictMode/UnannotatedWildcard.fir.kt | 2 +- ...AdaptationForReferenceCompatibility.fir.kt | 2 +- .../tests/cast/AsInBinaryUnary.fir.kt | 6 +++--- .../ifToAnyDiscriminatingUsages.fir.kt | 2 +- .../tests/controlStructures/kt10717.fir.kt | 4 ++-- .../ScalaLikeNamedFun.fir.kt | 16 ++++++++-------- .../genericMethodInGenericClass.fir.kt | 2 +- ...noOperatorModifierOnProvideDelegate.fir.kt | 2 +- .../typeMismatchForGetReturnType.fir.kt | 2 +- .../ReturnTypeCheck.fir.kt | 6 +++--- .../missedTypeMismatch.fir.kt | 4 ++-- .../IfWithoutElseWithExplicitType.fir.kt | 2 +- .../return/LocalReturnSecondUnit.fir.kt | 6 ------ .../return/LocalReturnSecondUnit.kt | 1 + .../LocalReturnsWithExplicitReturnType.fir.kt | 2 +- .../typeMismatchInLambda.fir.kt | 2 +- ...ToUnitForIfAsLastExpressionInLambda.fir.kt | 2 +- .../coercionWithExpectedType.fir.kt | 2 +- .../postponedArgumentsAnalysis/basic.fir.kt | 2 +- .../illegalUnderscoredTypeArgument.fir.kt | 2 +- .../tests/inference/kt28654.fir.kt | 2 +- .../tests/inference/kt49658Strict.fir.kt | 2 +- .../tests/inference/regressions/kt2286.fir.kt | 6 +++--- .../inference/regressions/kt37419.fir.kt | 12 ++++++------ .../tests/regressions/OutProjections.fir.kt | 2 +- .../tests/regressions/kt251.fir.kt | 6 +++--- .../javaMemberAgainstExtension.fir.kt | 2 +- .../tests/secondaryConstructors/return.fir.kt | 4 ++-- .../smartCasts/varnotnull/varIntNull.fir.kt | 2 +- .../return-expressions/p-4/neg/1.1.fir.kt | 2 +- .../introduction-1/p-6/neg/2.2.fir.kt | 2 +- 42 files changed, 82 insertions(+), 77 deletions(-) delete mode 100644 compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnSecondUnit.fir.kt diff --git a/analysis/analysis-api-fir/analysis-api-fir-generator/src/org/jetbrains/kotlin/analysis/api/fir/generator/HLDiagnosticConverter.kt b/analysis/analysis-api-fir/analysis-api-fir-generator/src/org/jetbrains/kotlin/analysis/api/fir/generator/HLDiagnosticConverter.kt index 6b316320566..a6957d7cf18 100644 --- a/analysis/analysis-api-fir/analysis-api-fir-generator/src/org/jetbrains/kotlin/analysis/api/fir/generator/HLDiagnosticConverter.kt +++ b/analysis/analysis-api-fir/analysis-api-fir-generator/src/org/jetbrains/kotlin/analysis/api/fir/generator/HLDiagnosticConverter.kt @@ -302,10 +302,10 @@ private object FirToKtConversionCreator { KtSymbol::class.createType(), importsToAdd = listOf("org.jetbrains.kotlin.fir.declarations.FirDeclaration") ), - FirSimpleFunction::class to HLFunctionCallConversion( + FirFunction::class to HLFunctionCallConversion( "firSymbolBuilder.buildSymbol({0})", KtSymbol::class.createType(), - importsToAdd = listOf("org.jetbrains.kotlin.fir.declarations.FirSimpleFunction") + importsToAdd = listOf("org.jetbrains.kotlin.fir.declarations.FirFunction") ), FirNamedFunctionSymbol::class to HLFunctionCallConversion( "firSymbolBuilder.functionLikeBuilder.buildFunctionSymbol({0})", diff --git a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt index c536f07a2fc..17ea1bbaf82 100644 --- a/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt +++ b/analysis/analysis-api-fir/src/org/jetbrains/kotlin/analysis/api/fir/diagnostics/KtFirDataClassConverters.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.builder.FirSyntaxErrors import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration import org.jetbrains.kotlin.fir.declarations.FirClass import org.jetbrains.kotlin.fir.declarations.FirDeclaration +import org.jetbrains.kotlin.fir.declarations.FirFunction import org.jetbrains.kotlin.fir.declarations.FirProperty import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/returnTypeMismatchOnOverride.kt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/returnTypeMismatchOnOverride.kt index f53bfbedc42..7958db93c98 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/returnTypeMismatchOnOverride.kt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/returnTypeMismatchOnOverride.kt @@ -57,7 +57,7 @@ open class J() : S() { } open class Base { - open fun kek(): Z = Z() + open fun kek(): Z = Z() } open class GoodDerrived : Base() { diff --git a/compiler/fir/analysis-tests/testData/resolve/expresssions/invoke/threeReceiversCorrect.kt b/compiler/fir/analysis-tests/testData/resolve/expresssions/invoke/threeReceiversCorrect.kt index f933a1bf3ed..1df176148c3 100644 --- a/compiler/fir/analysis-tests/testData/resolve/expresssions/invoke/threeReceiversCorrect.kt +++ b/compiler/fir/analysis-tests/testData/resolve/expresssions/invoke/threeReceiversCorrect.kt @@ -3,7 +3,7 @@ class C class B class A { - val B.foo: C.() -> Unit get() = null + val B.foo: C.() -> Unit get() = null } fun with(arg: T, f: T.() -> R): R = arg.f() diff --git a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantVisibilityModifierChecker.kt b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantVisibilityModifierChecker.kt index 25aae578b4c..32fac729800 100644 --- a/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantVisibilityModifierChecker.kt +++ b/compiler/fir/analysis-tests/testData/resolve/extendedCheckers/RedundantVisibilityModifierChecker.kt @@ -81,7 +81,7 @@ open class J { } var bar = 0 - get() = 3.1415926535 + get() = 3.1415926535 set(value) {} } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/diagnostics/functionReturnTypeMismatchChecker/basic.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/diagnostics/functionReturnTypeMismatchChecker/basic.kt index 78b5b3d7d1f..9b997ca7c49 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/diagnostics/functionReturnTypeMismatchChecker/basic.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/diagnostics/functionReturnTypeMismatchChecker/basic.kt @@ -12,7 +12,7 @@ fun ok(): Int { } fun okOneLineFunction(): Int = 10 + 1 -fun errorOneLineFunction(): String = 10 + 1 +fun errorOneLineFunction(): String = 10 + 1 class A { fun bar() {} @@ -37,7 +37,7 @@ fun errorWithLambda(): String { return@foo } foo { bar() - return@foo 10 + return@foo 10 } return "" diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/lightMember.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/lightMember.kt index df7c19b2c7a..17c055fd5c6 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/lightMember.kt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/lightMember.kt @@ -8,5 +8,5 @@ abstract class LightMemberImpl(computeRealDelegate: () -> D) abstract class LightFieldImpl(computeRealDelegate: () -> D) : LightMemberImpl(computeRealDelegate) { override val delegate: D - get() = super.delegate -} \ No newline at end of file + get() = super.delegate +} diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index dab4f39a93f..09cf73974b8 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -18,7 +18,7 @@ import org.jetbrains.kotlin.diagnostics.WhenMissingCase import org.jetbrains.kotlin.fir.FirModuleData import org.jetbrains.kotlin.fir.PrivateForInline import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.* -import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction +import org.jetbrains.kotlin.fir.declarations.FirFunction import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* @@ -624,7 +624,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") { val RETURN_TYPE_MISMATCH by error(PositioningStrategy.WHOLE_ELEMENT) { parameter("expectedType") parameter("actualType") - parameter("targetFunction") + parameter("targetFunction") parameter("isMismatchDueToNullability") } diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index faf546bc931..1caf31e657d 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -29,7 +29,7 @@ import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies import org.jetbrains.kotlin.diagnostics.WhenMissingCase import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory import org.jetbrains.kotlin.fir.FirModuleData -import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction +import org.jetbrains.kotlin.fir.declarations.FirFunction import org.jetbrains.kotlin.fir.expressions.FirExpression import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirBackingFieldSymbol @@ -393,7 +393,7 @@ object FirErrors { val REIFIED_TYPE_PARAMETER_NO_INLINE by error0(SourceElementPositioningStrategies.REIFIED_MODIFIER) val TYPE_PARAMETERS_NOT_ALLOWED by error0(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST) val TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER by error0() - val RETURN_TYPE_MISMATCH by error4(SourceElementPositioningStrategies.WHOLE_ELEMENT) + val RETURN_TYPE_MISMATCH by error4(SourceElementPositioningStrategies.WHOLE_ELEMENT) val CYCLIC_GENERIC_UPPER_BOUND by error0() val DEPRECATED_TYPE_PARAMETER_SYNTAX by error0(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST) val MISPLACED_TYPE_PARAMETER_CONSTRAINTS by warning0() diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt index ad212bd0d8c..9f21ca24bd8 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirFunctionReturnTypeMismatchChecker.kt @@ -5,14 +5,16 @@ package org.jetbrains.kotlin.fir.analysis.checkers.expression +import org.jetbrains.kotlin.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.diagnostics.reportOn import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext import org.jetbrains.kotlin.fir.analysis.checkers.isSubtypeForTypeMismatch -import org.jetbrains.kotlin.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NULL_FOR_NONNULL_TYPE import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.RETURN_TYPE_MISMATCH import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.SMARTCAST_IMPOSSIBLE -import org.jetbrains.kotlin.diagnostics.reportOn -import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction +import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction +import org.jetbrains.kotlin.fir.declarations.FirConstructor +import org.jetbrains.kotlin.fir.declarations.FirErrorFunction import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast import org.jetbrains.kotlin.fir.expressions.FirReturnExpression import org.jetbrains.kotlin.fir.expressions.FirWhenExpression @@ -23,12 +25,19 @@ object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() { override fun check(expression: FirReturnExpression, context: CheckerContext, reporter: DiagnosticReporter) { if (expression.source == null) return val targetElement = expression.target.labeledElement - if (targetElement !is FirSimpleFunction) return + if (targetElement is FirErrorFunction || + targetElement is FirAnonymousFunction && targetElement.isLambda && expression.target.labelName == null + ) { + return + } val resultExpression = expression.result // To avoid duplications with NO_ELSE_IN_WHEN or INVALID_IF_AS_EXPRESSION if (resultExpression is FirWhenExpression && !resultExpression.isExhaustive) return - val functionReturnType = targetElement.returnTypeRef.coneType + val functionReturnType = if (targetElement is FirConstructor) + context.session.builtinTypes.unitType.coneType + else + targetElement.returnTypeRef.coneType val typeContext = context.session.typeContext val returnExpressionType = resultExpression.typeRef.coneTypeSafe() ?: return diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirControlFlowStatementsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirControlFlowStatementsResolveTransformer.kt index 475b8694743..f3adb05e9c5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirControlFlowStatementsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirControlFlowStatementsResolveTransformer.kt @@ -194,7 +194,7 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirBodyResolveTran ResolutionMode.ContextDependent } else -> { - ResolutionMode.WithExpectedType(expectedTypeRef) + ResolutionMode.WithExpectedType(expectedTypeRef, expectedTypeMismatchIsReportedInChecker = true) } } diff --git a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.fir.kt b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.fir.kt index 88b59d781f4..f78aaad678d 100644 --- a/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.fir.kt +++ b/compiler/testData/diagnostics/foreignAnnotationsTests/java8Tests/jspecify/strictMode/UnannotatedWildcard.fir.kt @@ -15,4 +15,4 @@ public interface J2 { } // FILE: main.kt -fun baz(j2: J2): Any = j2.bar().foo() // Any..Any? +fun baz(j2: J2): Any = j2.bar().foo() // Any..Any? diff --git a/compiler/testData/diagnostics/tests/callableReference/unitAdaptationForReferenceCompatibility.fir.kt b/compiler/testData/diagnostics/tests/callableReference/unitAdaptationForReferenceCompatibility.fir.kt index 4d8efb74ac4..de30df9b0cc 100644 --- a/compiler/testData/diagnostics/tests/callableReference/unitAdaptationForReferenceCompatibility.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/unitAdaptationForReferenceCompatibility.fir.kt @@ -21,5 +21,5 @@ fun f(): String = "test" class A { fun schedule1(e: Executor): Future = e.submit(::f) - fun schedule2(e: Executor): Future = e.submit { f() } + fun schedule2(e: Executor): Future = e.submit { f() } } diff --git a/compiler/testData/diagnostics/tests/cast/AsInBinaryUnary.fir.kt b/compiler/testData/diagnostics/tests/cast/AsInBinaryUnary.fir.kt index 9ca7feee3e9..c7b2454e7fa 100644 --- a/compiler/testData/diagnostics/tests/cast/AsInBinaryUnary.fir.kt +++ b/compiler/testData/diagnostics/tests/cast/AsInBinaryUnary.fir.kt @@ -19,12 +19,12 @@ operator fun Impl2.unaryMinus() = Impl2() // See also KT-10384: in non-error functions, as is necessary! fun add1(x: Impl2, y: Base): Impl1 = x as Base + y -fun error1(x: Impl2, y: Base): Impl1 = x + y +fun error1(x: Impl2, y: Base): Impl1 = x + y fun add2(x: Base, y: Impl2): Impl1 = x + y as Base -fun error2(x: Base, y: Impl2): Impl1 = x + y +fun error2(x: Base, y: Impl2): Impl1 = x + y fun minus3(x: Impl2): Impl1 = -(x as Base) -fun error3(x: Impl2): Impl1 = -x +fun error3(x: Impl2): Impl1 = -x diff --git a/compiler/testData/diagnostics/tests/controlStructures/ifToAnyDiscriminatingUsages.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/ifToAnyDiscriminatingUsages.fir.kt index ded70b0c892..08cfe1922d8 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/ifToAnyDiscriminatingUsages.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/ifToAnyDiscriminatingUsages.fir.kt @@ -27,7 +27,7 @@ fun testResultOfAnonFun2() = fun testReturnFromAnonFun() = run(fun () { - return if (true) 42 else println() + return if (true) 42 else println() }) fun testReturn1() = diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt10717.fir.kt b/compiler/testData/diagnostics/tests/controlStructures/kt10717.fir.kt index 17d7e65b2ba..fd092171295 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt10717.fir.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt10717.fir.kt @@ -37,9 +37,9 @@ fun test4() = run { val foo: Int get() = run { - if (true) return "" + if (true) return "" - return + return } fun test(): Int = run { diff --git a/compiler/testData/diagnostics/tests/declarationChecks/ScalaLikeNamedFun.fir.kt b/compiler/testData/diagnostics/tests/declarationChecks/ScalaLikeNamedFun.fir.kt index c631a18cff1..fff3b719017 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/ScalaLikeNamedFun.fir.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/ScalaLikeNamedFun.fir.kt @@ -3,16 +3,16 @@ fun test1(): Int = { return 1 } fun test2(): Int = { 1 } -val test3: () -> Int = fun (): Int = { return 1 } -val test4: () -> Int = fun (): Int = { 1 } +val test3: () -> Int = fun (): Int = { return 1 } +val test4: () -> Int = fun (): Int = { 1 } fun test5(): Int { return { 1 } } fun test6(): Int = fun (): Int = 1 fun outer() { fun test1(): Int = { return 1 } fun test2(): Int = { 1 } - val test3: () -> Int = fun (): Int = { return 1 } - val test4: () -> Int = fun (): Int = { 1 } + val test3: () -> Int = fun (): Int = { return 1 } + val test4: () -> Int = fun (): Int = { 1 } fun test5(): Int { return { 1 } } fun test6(): Int = fun (): Int = 1 } @@ -20,16 +20,16 @@ fun outer() { class Outer { fun test1(): Int = { return 1 } fun test2(): Int = { 1 } - val test3: () -> Int = fun (): Int = { return 1 } - val test4: () -> Int = fun (): Int = { 1 } + val test3: () -> Int = fun (): Int = { return 1 } + val test4: () -> Int = fun (): Int = { 1 } fun test5(): Int { return { 1 } } fun test6(): Int = fun (): Int = 1 class Nested { fun test1(): Int = { return 1 } fun test2(): Int = { 1 } - val test3: () -> Int = fun (): Int = { return 1 } - val test4: () -> Int = fun (): Int = { 1 } + val test3: () -> Int = fun (): Int = { return 1 } + val test4: () -> Int = fun (): Int = { 1 } fun test5(): Int { return { 1 } } fun test6(): Int = fun (): Int = 1 } diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt index 47aaedbea0c..6c2b0d91eff 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/inference/genericMethodInGenericClass.fir.kt @@ -24,4 +24,4 @@ class C() { } var c1: Int by C() -var c2: Int by C() +var c2: Int by C() diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.fir.kt index b4c5584cbb1..648295eb2c4 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/provideDelegate/noOperatorModifierOnProvideDelegate.fir.kt @@ -12,5 +12,5 @@ fun String.provideDelegate(a: Any?, p: KProperty<*>) = StringDelegate(this) operator fun String.getValue(a: Any?, p: KProperty<*>) = this val test1: String by "OK" -val test2: Int by "OK" +val test2: Int by "OK" val test3 by "OK" diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.fir.kt index 9f87631f031..faf7937226b 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/typeMismatchForGetReturnType.fir.kt @@ -2,7 +2,7 @@ import kotlin.reflect.KProperty -val c: Int by Delegate() +val c: Int by Delegate() class Delegate { operator fun getValue(t: Any?, p: KProperty<*>): String { diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/ReturnTypeCheck.fir.kt b/compiler/testData/diagnostics/tests/functionAsExpression/ReturnTypeCheck.fir.kt index c811328fbbb..1b4713fb262 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/ReturnTypeCheck.fir.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/ReturnTypeCheck.fir.kt @@ -2,8 +2,8 @@ val foo = fun(a: Int): String { if (a == 1) return "4" when (a) { 5 -> return "2" - 3 -> return null - 2 -> return 2 + 3 -> return null + 2 -> return 2 } return "" -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/missedTypeMismatch.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/missedTypeMismatch.fir.kt index 45b31635789..d5fe7f45e5b 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/missedTypeMismatch.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/missedTypeMismatch.fir.kt @@ -11,8 +11,8 @@ fun main() { val a0: () -> Int = fun(): String = "1" val a1: () -> Int = (fun() = "1") - val a2: () -> Unit = (fun() = "1") - val a3: Unit = (fun() = "1") + val a2: () -> Unit = (fun() = "1") + val a3: Unit = (fun() = "1") val a4 = (fun() = "1") val a5 = (fun(): String = "1") val a6: () -> Int = (fun() = 1) diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.fir.kt index fecb9ea5bf4..e39438c48f3 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.fir.kt @@ -5,7 +5,7 @@ val a: () -> Int = l@ { } val b: () -> Unit = l@ { - if (flag) return@l 4 + if (flag) return@l 4 } val c: () -> Any = l@ { diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnSecondUnit.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnSecondUnit.fir.kt deleted file mode 100644 index 7f02acdf15b..00000000000 --- a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnSecondUnit.fir.kt +++ /dev/null @@ -1,6 +0,0 @@ -val flag = true - -val a = b@ { - if (flag) return@b 4 - return@b -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnSecondUnit.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnSecondUnit.kt index 280e2b42b4e..11d8ab569cd 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnSecondUnit.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnSecondUnit.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL val flag = true val a = b@ { diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnsWithExplicitReturnType.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnsWithExplicitReturnType.fir.kt index e5f864f2baa..959a6fdc54d 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnsWithExplicitReturnType.fir.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnsWithExplicitReturnType.fir.kt @@ -1,6 +1,6 @@ fun test(a: Int) { runf@{ - if (a > 0) return@f "" + if (a > 0) return@f "" return@f 1 } diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchInLambda.fir.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchInLambda.fir.kt index c71c7c06a0f..ba6cde6ace1 100644 --- a/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchInLambda.fir.kt +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/typeMismatchInLambda.fir.kt @@ -20,7 +20,7 @@ fun test(a: A, z: Out) { a.bar { z.id() } a.foo { - z.foobar(if (1 > 2) return@foo "" else "") + z.foobar(if (1 > 2) return@foo "" else "") "" } } diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitForIfAsLastExpressionInLambda.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitForIfAsLastExpressionInLambda.fir.kt index b4c414777da..fad8594a36a 100644 --- a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitForIfAsLastExpressionInLambda.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionToUnitForIfAsLastExpressionInLambda.fir.kt @@ -12,7 +12,7 @@ fun foo(): String? { run { if (true) return@run - if (true) return Obj() // correct error, type check against return type of function "foo" + if (true) return Obj() // correct error, type check against return type of function "foo" } run { diff --git a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedType.fir.kt b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedType.fir.kt index 5fa78bd038f..b346199bf14 100644 --- a/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedType.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedType.fir.kt @@ -12,7 +12,7 @@ val a: () -> Unit = l@{ val b: () -> Unit = l@{ // Error, coercion can't be applied at this position! - if (true) return@l "hello" + if (true) return@l "hello" // However, this is OK, because here coercion is applied "hello" 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 d2dfa2a385d..bbb3aa5a498 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/basic.fir.kt @@ -103,7 +103,7 @@ fun main() { select( id { x, y -> x.inv() + y.toByte() }, id<(Int, Number) -> Int> { x, y -> x.inv() }, - {} as (Number, Number) -> Int + {} as (Number, Number) -> Int ) // Inferring lambda parameter types by a few expected types (a few upper constraints) diff --git a/compiler/testData/diagnostics/tests/inference/illegalUnderscoredTypeArgument.fir.kt b/compiler/testData/diagnostics/tests/inference/illegalUnderscoredTypeArgument.fir.kt index 2a3a8746fad..786376f0ae2 100644 --- a/compiler/testData/diagnostics/tests/inference/illegalUnderscoredTypeArgument.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/illegalUnderscoredTypeArgument.fir.kt @@ -7,4 +7,4 @@ class Foo fun main() { val x = foo_>> { it.toFloat() } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/inference/kt28654.fir.kt b/compiler/testData/diagnostics/tests/inference/kt28654.fir.kt index f1462e61313..874cd51edd0 100644 --- a/compiler/testData/diagnostics/tests/inference/kt28654.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/kt28654.fir.kt @@ -1,7 +1,7 @@ // !DIAGNOSTICS: -UNUSED_VARIABLE // Related issue: KT-28654 -fun select(): K = run { } +fun select(): K = run { } fun test() { val x: Int = select() diff --git a/compiler/testData/diagnostics/tests/inference/kt49658Strict.fir.kt b/compiler/testData/diagnostics/tests/inference/kt49658Strict.fir.kt index 435095978c3..d50cd82a346 100644 --- a/compiler/testData/diagnostics/tests/inference/kt49658Strict.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/kt49658Strict.fir.kt @@ -14,4 +14,4 @@ fun doTheMapThing2(elements: List): List { return elements.flatMap { if (it is String) listOf("Yeah") else null // it's OK with `if` } -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2286.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2286.fir.kt index ec488fbf8bb..05160d56d8a 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2286.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2286.fir.kt @@ -11,14 +11,14 @@ abstract class Buggy { } val anotherThree : Int - get() = coll.find{ it > 3 } // does not work here + get() = coll.find{ it > 3 } // does not work here val yetAnotherThree : Int - get() = coll.find({ v:Int -> v > 3 }) // neither here + get() = coll.find({ v:Int -> v > 3 }) // neither here val extendedGetter : Int get() { - return coll.find{ it > 3 } // not even here! + return coll.find{ it > 3 } // not even here! } } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt37419.fir.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt37419.fir.kt index 6e3ee39e421..11abafacedd 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt37419.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt37419.fir.kt @@ -15,18 +15,18 @@ class SomeClass { val e = E.VALUE val withoutType: LambdaWithReceiver - get() = when (e) { + get() = when (e) { E.VALUE -> { param -> method(param) } - } + } val withExplicitType: LambdaWithReceiver - get() = when (e) { + get() = when (e) { E.VALUE -> { param: Parameter -> method(param) } - } + } } class OtherClass { @@ -38,8 +38,8 @@ class OtherClass { val e2 = E.VALUE val staticWithExplicitType: LambdaWithReceiver - get() = when (e2) { + get() = when (e2) { E.VALUE -> { param: Parameter -> method(param) } - } + } diff --git a/compiler/testData/diagnostics/tests/regressions/OutProjections.fir.kt b/compiler/testData/diagnostics/tests/regressions/OutProjections.fir.kt index f645dbbd820..703e1c4963b 100644 --- a/compiler/testData/diagnostics/tests/regressions/OutProjections.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/OutProjections.fir.kt @@ -8,7 +8,7 @@ fun f(expression : T) : G = G() fun foo() : G { val p = Point() - return f(p) + return f(p) } class Out() {} diff --git a/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt index a4ab77ebd2a..26b4b3aa49e 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt251.fir.kt @@ -1,6 +1,6 @@ class A() { var x: Int = 0 - get() = "s" + get() = "s" set(value: String) { field = value } @@ -8,7 +8,7 @@ class A() { get(): String = "s" val z: Int get() { - return "s" + return "s" } var a: Any = 1 @@ -27,7 +27,7 @@ class A() { } val e = 1 get(): String { - return field + return field } } diff --git a/compiler/testData/diagnostics/tests/samConversions/javaMemberAgainstExtension.fir.kt b/compiler/testData/diagnostics/tests/samConversions/javaMemberAgainstExtension.fir.kt index 2b866cb4c7f..f952cdcf97a 100644 --- a/compiler/testData/diagnostics/tests/samConversions/javaMemberAgainstExtension.fir.kt +++ b/compiler/testData/diagnostics/tests/samConversions/javaMemberAgainstExtension.fir.kt @@ -16,7 +16,7 @@ fun LiveData.observe(a: Any, observer: (T) -> Unit): Observer { } // FILE: test.kt -fun test1(r: Runnable, l: LiveData): Observer = l.observe(r) { } // partial conversion +fun test1(r: Runnable, l: LiveData): Observer = l.observe(r) { } // partial conversion fun test2(r: Runnable, o: Observer, l: LiveData) { val a = l.observe(r, o) // no conversion diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/return.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/return.fir.kt index 9fb85b4e5ee..641a4f2f213 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/return.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/return.fir.kt @@ -6,10 +6,10 @@ class A { constructor() { if (1 == 1) { return - return 1 + return 1 } return - return foo() + return foo() } fun foo(): Int = 1 diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.fir.kt index b8626eb17fa..17468d17402 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.fir.kt @@ -1,5 +1,5 @@ fun foo(): Int { var i: Int? = 42 i = null - return i + 1 + return i + 1 } diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/jump-expressions/return-expressions/p-4/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/jump-expressions/return-expressions/p-4/neg/1.1.fir.kt index 0fe93689183..50fe1c4342d 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/jump-expressions/return-expressions/p-4/neg/1.1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/jump-expressions/return-expressions/p-4/neg/1.1.fir.kt @@ -9,4 +9,4 @@ fun case1(a: Boolean) = run { println("d"); return true< // TESTCASE NUMBER: 2 val case2 -get() = run { println("d"); return true } +get() = run { println("d"); return true } diff --git a/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.2.fir.kt index d7774ccdef1..b16e30f969c 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/type-system/introduction-1/p-6/neg/2.2.fir.kt @@ -30,7 +30,7 @@ class Case6 { // TESTCASE NUMBER: 7 class Case7 { - val x: Int get() = null + val x: Int get() = null } // TESTCASE NUMBER: 8