From 1c0fd7342fcbb20c39b31b17b54f691dc60fe7da Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Fri, 6 Mar 2020 14:11:31 +0300 Subject: [PATCH] [FIR] Support completion of lambdas with type variable as expected type #KT-37310 Fixed #KT-37304 Fixed --- .../kotlin/fir/resolve/calls/Arguments.kt | 2 +- .../fir/resolve/inference/FirCallCompleter.kt | 2 +- .../resolve/inference/InferenceCompletion.kt | 117 ++++++++++++++++-- .../resolve/inference/PostponedArguments.kt | 62 +++++++--- .../inference/PostponedArgumentsAnalyzer.kt | 33 +++-- .../FirDeclarationsResolveTransformer.kt | 3 +- .../resolve/cfg/lambdaAsReturnOfLambda.dot | 4 +- .../resolve/cfg/lambdaAsReturnOfLambda.kt | 2 +- .../resolve/cfg/lambdaAsReturnOfLambda.txt | 4 +- .../resolve/lambdaPropertyTypeInference.kt | 8 +- .../resolve/lambdaPropertyTypeInference.txt | 40 +++--- .../delegates/delegateTypeMismatch.kt | 2 +- .../delegates/delegateTypeMismatch.txt | 12 +- .../delegates/propertyWithFunctionalType.kt | 12 ++ .../delegates/propertyWithFunctionalType.txt | 35 ++++++ ...FirDiagnosticsWithStdlibTestGenerated.java | 5 + .../functionLiteralAsLastExpressionInBlock.kt | 1 - .../lambdaAsLastExpressionInLambda.kt | 1 - .../constraints/returnLambdaFromLambda.fir.kt | 2 +- .../diagnostics/tests/inference/kt3184.fir.kt | 26 ---- .../diagnostics/tests/inference/kt3184.kt | 1 + ...9returnTypeWithTypealiasSubtitution.fir.kt | 37 ------ ...32189returnTypeWithTypealiasSubtitution.kt | 1 + .../tests/regressions/kt10843.fir.kt | 2 +- .../tests/regressions/kt30245.fir.kt | 10 +- .../resolveWithFunctionLiteralWithId.fir.kt | 32 ----- .../resolveWithFunctionLiteralWithId.kt | 1 + ...eWithSpecifiedFunctionLiteralWithId.fir.kt | 10 +- 28 files changed, 281 insertions(+), 186 deletions(-) create mode 100644 compiler/fir/resolve/testData/resolveWithStdlib/delegates/propertyWithFunctionalType.kt create mode 100644 compiler/fir/resolve/testData/resolveWithStdlib/delegates/propertyWithFunctionalType.txt delete mode 100644 compiler/testData/diagnostics/tests/inference/kt3184.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitution.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralWithId.fir.kt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt index 8749b12a24a..cf59e1fd3f1 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt @@ -49,7 +49,7 @@ fun Candidate.resolveArgumentExpression( isDispatch: Boolean, isSafeCall: Boolean ) { - return when (argument) { + when (argument) { is FirFunctionCall, is FirWhenExpression, is FirTryExpression, is FirCheckNotNullCall -> resolveSubCallArgument( csBuilder, argument as FirResolvable, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt index 8face419413..95e1f176d6c 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/FirCallCompleter.kt @@ -41,7 +41,7 @@ class FirCallCompleter( private val transformer: FirBodyResolveTransformer, components: FirAbstractBodyResolveTransformer.BodyResolveTransformerComponents ) : BodyResolveComponents by components { - val completer = ConstraintSystemCompleter(components.inferenceComponents) + val completer = ConstraintSystemCompleter(components) private val inferenceSession get() = inferenceComponents.inferenceSession diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceCompletion.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceCompletion.kt index 897cd2747ba..6169a4147d7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceCompletion.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/InferenceCompletion.kt @@ -6,17 +6,18 @@ package org.jetbrains.kotlin.fir.resolve.inference import org.jetbrains.kotlin.fir.expressions.* +import org.jetbrains.kotlin.fir.resolve.BodyResolveComponents import org.jetbrains.kotlin.fir.resolve.calls.Candidate import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate import org.jetbrains.kotlin.fir.returnExpressions -import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralType -import org.jetbrains.kotlin.fir.types.ConeKotlinType -import org.jetbrains.kotlin.fir.types.ConeTypeVariable -import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl +import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter import org.jetbrains.kotlin.resolve.calls.inference.components.TypeVariableDirectionCalculator import org.jetbrains.kotlin.resolve.calls.inference.components.VariableFixationFinder import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl +import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker import org.jetbrains.kotlin.types.model.KotlinTypeMarker @@ -94,8 +95,8 @@ private fun Candidate.hasProperNonTrivialLowerConstraints(components: InferenceC } -class ConstraintSystemCompleter(val components: InferenceComponents) { - private val variableFixationFinder = VariableFixationFinder(components.trivialConstraintTypeInferenceOracle) +class ConstraintSystemCompleter(private val components: BodyResolveComponents) { + private val variableFixationFinder = VariableFixationFinder(components.inferenceComponents.trivialConstraintTypeInferenceOracle) fun complete( c: KotlinConstraintSystemCompleter.Context, @@ -109,16 +110,18 @@ class ConstraintSystemCompleter(val components: InferenceComponents) { if (analyzePostponeArgumentIfPossible(c, topLevelAtoms, analyze)) continue val allTypeVariables = getOrderedAllTypeVariables(c, topLevelAtoms) - val postponedKtPrimitives = getOrderedNotAnalyzedPostponedArguments(topLevelAtoms) + val postponedAtoms = getOrderedNotAnalyzedPostponedArguments(topLevelAtoms) val variableForFixation = variableFixationFinder.findFirstVariableForFixation( - c, allTypeVariables, postponedKtPrimitives, completionMode, candidateReturnType + c, allTypeVariables, postponedAtoms, completionMode, candidateReturnType ) ?: break -// if (shouldForceCallableReferenceOrLambdaResolution(completionMode, variableForFixation)) { -// if (forcePostponedAtomResolution(topLevelAtoms, analyze)) continue -// if (forcePostponedAtomResolution(topLevelAtoms, analyze)) continue -// } + if ( + completionMode == KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode.FULL && + resolveLambdaOrCallableReferenceWithTypeVariableAsExpectedType(c, variableForFixation, postponedAtoms, analyze) + ) { + continue + } if (variableForFixation.hasProperConstraint || completionMode == KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode.FULL) { val variableWithConstraints = c.notFixedTypeVariables.getValue(variableForFixation.variable) @@ -144,6 +147,89 @@ class ConstraintSystemCompleter(val components: InferenceComponents) { } } + private fun resolveLambdaOrCallableReferenceWithTypeVariableAsExpectedType( + c: KotlinConstraintSystemCompleter.Context, + variableForFixation: VariableFixationFinder.VariableForFixation, + postponedAtoms: List, + /*diagnosticsHolder: KotlinDiagnosticsHolder,*/ + analyze: (PostponedResolvedAtom) -> Unit + ): Boolean { + val variable = variableForFixation.variable as ConeTypeVariableTypeConstructor + val hasProperAtom = postponedAtoms.any { + when (it) { + is LambdaWithTypeVariableAsExpectedTypeAtom/*, is PostponedCallableReferenceAtom*/ + -> it.expectedType.typeConstructor(c) == variable // TODO + else -> false + } + } + if ( + !hasProperAtom && + variableForFixation.hasProperConstraint && + !variableForFixation.hasOnlyTrivialProperConstraint + ) return false + + val postponedAtom = postponedAtoms.firstOrNull() ?: return false + val csBuilder = (c as NewConstraintSystemImpl).getBuilder() + val expectedTypeVariableConstructor = postponedAtom.expectedType?.typeConstructor(c)?.takeIf { it in c.allTypeVariables } as? ConeTypeVariableTypeConstructor ?: variable + val expectedTypeVariable = csBuilder.currentStorage().allTypeVariables[expectedTypeVariableConstructor] as ConeTypeVariable? ?: return false + + val atomToAnalyze = when (postponedAtom) { + is LambdaWithTypeVariableAsExpectedTypeAtom -> { + postponedAtom.preparePostponedAtomWithTypeVariableAsExpectedType( + c, csBuilder, expectedTypeVariable, + parameterTypes = null, + isSuitable = { isBuiltinFunctionalType(components.session) }, + typeVariableCreator = { ConeTypeVariableForLambdaReturnType(postponedAtom.atom, "_R") }, + newAtomCreator = { returnTypeVariable, expectedType -> + postponedAtom.transformToResolvedLambda(csBuilder, expectedType, returnTypeVariable) + } + ) + } + // is PostponedCallableReferenceAtom -> TODO() + else -> return false + } + analyze(atomToAnalyze) + return true + } + + private inline fun T.preparePostponedAtomWithTypeVariableAsExpectedType( + c: KotlinConstraintSystemCompleter.Context, + csBuilder: ConstraintSystemBuilder, + variable: ConeTypeVariable, + parameterTypes: Array?, + isSuitable: ConeKotlinType.() -> Boolean, + typeVariableCreator: () -> V, + newAtomCreator: (V, ConeKotlinType) -> PostponedResolvedAtom + ): PostponedResolvedAtom { + val functionalType = (components.inferenceComponents.resultTypeResolver.findResultType( + c, + c.notFixedTypeVariables.getValue(variable.typeConstructor), + TypeVariableDirectionCalculator.ResolveDirection.TO_SUPERTYPE + ) as ConeKotlinType).lowerBoundIfFlexible() as ConeClassLikeType + val isExtensionWithoutParameters = false +// TODO +// functionalType.isExtensionFunctionType && functionalType.arguments.size == 2 && parameterTypes?.isEmpty() == true + if (parameterTypes?.all { type -> type != null } == true && !isExtensionWithoutParameters) return this + if (!functionalType.isSuitable()) return this + val returnVariable = typeVariableCreator() + csBuilder.registerVariable(returnVariable) + + val expectedType = ConeClassLikeTypeImpl( + lookupTag = functionalType.lookupTag, + typeArguments = (functionalType.typeArguments.dropLast(1) + returnVariable.defaultType).toTypedArray(), + isNullable = functionalType.isNullable + ) + + csBuilder.addSubtypeConstraint( + expectedType, + variable.defaultType, + SimpleConstraintSystemConstraintPosition +// ArgumentConstraintPosition(atom as KotlinCallArgument) + ) + return newAtomCreator(returnVariable, expectedType) + } + + private fun getOrderedAllTypeVariables( c: KotlinConstraintSystemCompleter.Context, topLevelAtoms: List @@ -158,6 +244,11 @@ class ConstraintSystemCompleter(val components: InferenceComponents) { typeVariable.toTypeConstructor() } + for (postponedAtom in candidate.postponedAtoms) { + when (postponedAtom) { + is ResolvedLambdaAtom -> postponedAtom.typeVariableForLambdaReturnType + } + } for (lambdaAtom in candidate.postponedAtoms.filterIsInstance()) { result.addIfNotNull(lambdaAtom.typeVariableForLambdaReturnType.toTypeConstructor()) } @@ -191,7 +282,7 @@ class ConstraintSystemCompleter(val components: InferenceComponents) { variableWithConstraints: VariableWithConstraints, direction: TypeVariableDirectionCalculator.ResolveDirection ) { - val resultType = components.resultTypeResolver.findResultType(c, variableWithConstraints, direction) + val resultType = components.inferenceComponents.resultTypeResolver.findResultType(c, variableWithConstraints, direction) c.fixVariable(variableWithConstraints.typeVariable, resultType, atom = null) // TODO: obtain atom for diagnostics } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt index bc83ada8948..f96d1cda940 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArguments.kt @@ -30,15 +30,16 @@ fun Candidate.preprocessLambdaArgument( argument: FirAnonymousFunction, expectedType: ConeKotlinType?, expectedTypeRef: FirTypeRef, - forceResolution: Boolean = false -) { + forceResolution: Boolean = false, + returnTypeVariable: ConeTypeVariableForLambdaReturnType? = null +): PostponedResolvedAtom { if (expectedType != null && !forceResolution && csBuilder.isTypeVariable(expectedType)) { - //return LambdaWithTypeVariableAsExpectedTypeAtom(argument, expectedType) + return LambdaWithTypeVariableAsExpectedTypeAtom(argument, expectedType, expectedTypeRef, this) } val resolvedArgument = - extractLambdaInfoFromFunctionalType(expectedType, expectedTypeRef, argument, bodyResolveComponents.session, bodyResolveComponents) - ?: extraLambdaInfo(expectedType, argument, csBuilder, bodyResolveComponents.session, bodyResolveComponents) + extractLambdaInfoFromFunctionalType(expectedType, expectedTypeRef, argument, returnTypeVariable, bodyResolveComponents, this) + ?: extraLambdaInfo(expectedType, argument, csBuilder, bodyResolveComponents.session, this) if (expectedType != null) { // TODO: add SAM conversion processing @@ -46,7 +47,7 @@ fun Candidate.preprocessLambdaArgument( csBuilder.addSubtypeConstraint(lambdaType, expectedType, SimpleConstraintSystemConstraintPosition) } - postponedAtoms += resolvedArgument + return resolvedArgument } fun Candidate.preprocessCallableReference( @@ -103,7 +104,7 @@ private fun extraLambdaInfo( argument: FirAnonymousFunction, csBuilder: ConstraintSystemBuilder, session: FirSession, - components: BodyResolveComponents + candidate: Candidate? ): ResolvedLambdaAtom { val isSuspend = expectedType?.isSuspendFunctionType(session) ?: false @@ -111,7 +112,7 @@ private fun extraLambdaInfo( expectedType != null && expectedType.lowerBoundIfFlexible() .isBuiltinFunctionalType(session)//isNotNullOrNullableFunctionSupertype(expectedType) - val typeVariable = TypeVariableForLambdaReturnType(argument, "_L") + val typeVariable = ConeTypeVariableForLambdaReturnType(argument, "_L") val receiverType = argument.receiverType val returnType = @@ -129,11 +130,13 @@ private fun extraLambdaInfo( return ResolvedLambdaAtom( argument, + expectedType, isSuspend, receiverType, parameters, returnType, - typeVariable.takeIf { newTypeVariableUsed } + typeVariable.takeIf { newTypeVariableUsed }, + candidate ) } @@ -141,12 +144,14 @@ internal fun extractLambdaInfoFromFunctionalType( expectedType: ConeKotlinType?, expectedTypeRef: FirTypeRef, argument: FirAnonymousFunction, - session: FirSession, - components: BodyResolveComponents + returnTypeVariable: ConeTypeVariableForLambdaReturnType?, + components: BodyResolveComponents, + candidate: Candidate? ): ResolvedLambdaAtom? { + val session = components.session if (expectedType == null) return null if (expectedType is ConeFlexibleType) { - return extractLambdaInfoFromFunctionalType(expectedType.lowerBound, expectedTypeRef, argument, session, components) + return extractLambdaInfoFromFunctionalType(expectedType.lowerBound, expectedTypeRef, argument, returnTypeVariable, components, candidate) } if (!expectedType.isBuiltinFunctionalType(session)) return null @@ -156,11 +161,13 @@ internal fun extractLambdaInfoFromFunctionalType( return ResolvedLambdaAtom( argument, + expectedType, expectedType.isSuspendFunctionType(session), receiverType, parameters, returnType, - typeVariableForLambdaReturnType = null + typeVariableForLambdaReturnType = returnTypeVariable, + candidate ) } @@ -196,31 +203,54 @@ private fun ConeKotlinType.extractParametersForFunctionalType( } } -class TypeVariableForLambdaReturnType(val argument: FirAnonymousFunction, name: String) : ConeTypeVariable(name) +class ConeTypeVariableForLambdaReturnType(val argument: FirAnonymousFunction, name: String) : ConeTypeVariable(name) sealed class PostponedResolvedAtom : PostponedResolvedAtomMarker { abstract override val inputTypes: Collection abstract override val outputType: ConeKotlinType? override var analyzed: Boolean = false + abstract val expectedType: ConeKotlinType? } class ResolvedLambdaAtom( val atom: FirAnonymousFunction, + override val expectedType: ConeKotlinType?, val isSuspend: Boolean, val receiver: ConeKotlinType?, val parameters: List, val returnType: ConeKotlinType, - val typeVariableForLambdaReturnType: TypeVariableForLambdaReturnType? + val typeVariableForLambdaReturnType: ConeTypeVariableForLambdaReturnType?, + val candidateForOuterCall: Candidate? ) : PostponedResolvedAtom() { + init { + candidateForOuterCall?.let { + it.postponedAtoms += this + } + } + lateinit var returnStatements: Collection override val inputTypes: Collection get() = receiver?.let { parameters + it } ?: parameters override val outputType: ConeKotlinType get() = returnType } +class LambdaWithTypeVariableAsExpectedTypeAtom( + val atom: FirAnonymousFunction, + override val expectedType: ConeKotlinType, + val expectedTypeRef: FirTypeRef, + val candidateForOuterCall: Candidate +) : PostponedResolvedAtom() { + init { + candidateForOuterCall.postponedAtoms += this + } + + override val inputTypes: Collection get() = listOf(expectedType) + override val outputType: ConeKotlinType? get() = null +} + class ResolvedCallableReferenceAtom( val reference: FirCallableReferenceAccess, - val expectedType: ConeKotlinType?, + override val expectedType: ConeKotlinType?, val lhs: DoubleColonLHS?, private val session: FirSession ) : PostponedResolvedAtom() { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt index b32167b1285..4da0e4eaf6b 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/inference/PostponedArgumentsAnalyzer.kt @@ -11,14 +11,15 @@ import org.jetbrains.kotlin.fir.expressions.FirStatement import org.jetbrains.kotlin.fir.references.builder.buildErrorNamedReference import org.jetbrains.kotlin.fir.resolve.calls.* import org.jetbrains.kotlin.fir.resolve.diagnostics.FirUnresolvedReferenceError +import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.transformers.StoreNameReference import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.ConeTypeVariable import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer +import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder import org.jetbrains.kotlin.resolve.calls.inference.model.CoroutinePosition import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition -import org.jetbrains.kotlin.resolve.calls.model.PostponedResolvedAtomMarker import org.jetbrains.kotlin.types.model.StubTypeMarker import org.jetbrains.kotlin.types.model.TypeVariableMarker import org.jetbrains.kotlin.types.model.freshTypeConstructor @@ -53,17 +54,15 @@ class PostponedArgumentsAnalyzer( candidate: Candidate //diagnosticsHolder: KotlinDiagnosticsHolder ) { - when (argument) { + return when (argument) { is ResolvedLambdaAtom -> analyzeLambda(c, argument, candidate/*, diagnosticsHolder*/) -// is LambdaWithTypeVariableAsExpectedTypeAtom -> -// analyzeLambda( -// c, resolutionCallbacks, argument.transformToResolvedLambda(c.getBuilder()), diagnosticsHolder -// ) + is LambdaWithTypeVariableAsExpectedTypeAtom -> + analyzeLambda(c, argument.transformToResolvedLambda(c.getBuilder()), candidate/*, diagnosticsHolder*/) is ResolvedCallableReferenceAtom -> processCallableReference(argument, candidate) -// + // is ResolvedCollectionLiteralAtom -> TODO("Not supported") } } @@ -184,4 +183,22 @@ class PostponedArgumentsAnalyzer( } } - +fun LambdaWithTypeVariableAsExpectedTypeAtom.transformToResolvedLambda( + csBuilder: ConstraintSystemBuilder, + /*diagnosticHolder: KotlinDiagnosticsHolder,*/ + expectedType: ConeKotlinType? = null, + returnTypeVariable: ConeTypeVariableForLambdaReturnType? = null +): ResolvedLambdaAtom { + val fixedExpectedType = (csBuilder.buildCurrentSubstitutor() as ConeSubstitutor) + .substituteOrSelf(expectedType ?: this.expectedType) + val resolvedAtom = candidateOfOuterCall.preprocessLambdaArgument( + csBuilder, + atom, + fixedExpectedType, + expectedTypeRef, + forceResolution = true, + returnTypeVariable + ) as ResolvedLambdaAtom + analyzed = true + return resolvedAtom +} \ No newline at end of file diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index 2510529da4d..da71b3077ed 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -35,7 +35,6 @@ import org.jetbrains.kotlin.fir.types.builder.buildImplicitTypeRef import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef import org.jetbrains.kotlin.fir.visitors.* import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.utils.addIfNotNull class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer) : FirPartialBodyResolveTransformer(transformer) { private var primaryConstructorParametersScope: FirLocalScope? = null @@ -491,7 +490,7 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer) val expectedTypeRef = (data as? ResolutionMode.WithExpectedType)?.expectedTypeRef ?: buildImplicitTypeRef() val resolvedLambdaAtom = (expectedTypeRef as? FirResolvedTypeRef)?.let { extractLambdaInfoFromFunctionalType( - it.type, it, anonymousFunction, session, components + it.type, it, anonymousFunction, returnTypeVariable = null, components, candidate = null ) } var af = anonymousFunction diff --git a/compiler/fir/resolve/testData/resolve/cfg/lambdaAsReturnOfLambda.dot b/compiler/fir/resolve/testData/resolve/cfg/lambdaAsReturnOfLambda.dot index d49f62c48a6..907950d521d 100644 --- a/compiler/fir/resolve/testData/resolve/cfg/lambdaAsReturnOfLambda.dot +++ b/compiler/fir/resolve/testData/resolve/cfg/lambdaAsReturnOfLambda.dot @@ -6,7 +6,7 @@ digraph lambdaAsReturnOfLambda_kt { subgraph cluster_0 { color=red 0 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; - 1 [label="Jump: ^@run lambda@fun (foo: R|ERROR CLASS: No type for parameter|): R|kotlin/Unit| { + 1 [label="Jump: ^@run lambda@fun (foo: R|kotlin/String|): R|kotlin/Unit| { R|/bar|(R|/foo|) } "]; @@ -44,7 +44,7 @@ digraph lambdaAsReturnOfLambda_kt { 10 [label="Enter property" style="filled" fillcolor=red]; 11 [label="Postponed enter to lambda"]; 12 [label="Postponed exit from lambda"]; - 13 [label="Function call: R|/run| kotlin/Unit|>( = run@fun (): R|(ERROR CLASS: No type for parameter) -> kotlin/Unit|)"]; + 13 [label="Function call: R|/run| kotlin/Unit|>( = run@fun (): R|(kotlin/String) -> kotlin/Unit|)"]; 14 [label="Exit property" style="filled" fillcolor=red]; } diff --git a/compiler/fir/resolve/testData/resolve/cfg/lambdaAsReturnOfLambda.kt b/compiler/fir/resolve/testData/resolve/cfg/lambdaAsReturnOfLambda.kt index d660c2985be..14dc2beb1bd 100644 --- a/compiler/fir/resolve/testData/resolve/cfg/lambdaAsReturnOfLambda.kt +++ b/compiler/fir/resolve/testData/resolve/cfg/lambdaAsReturnOfLambda.kt @@ -1,7 +1,7 @@ // !DUMP_CFG val x4: (String) -> Unit = run { - return@run (lambda@{ foo -> + return@run (lambda@{ foo: String -> bar(foo) }) } diff --git a/compiler/fir/resolve/testData/resolve/cfg/lambdaAsReturnOfLambda.txt b/compiler/fir/resolve/testData/resolve/cfg/lambdaAsReturnOfLambda.txt index d15897f5d68..de61711d288 100644 --- a/compiler/fir/resolve/testData/resolve/cfg/lambdaAsReturnOfLambda.txt +++ b/compiler/fir/resolve/testData/resolve/cfg/lambdaAsReturnOfLambda.txt @@ -1,6 +1,6 @@ FILE: lambdaAsReturnOfLambda.kt - public final val x4: R|(kotlin/String) -> kotlin/Unit| = R|/run| kotlin/Unit|>( = run@fun (): R|(ERROR CLASS: No type for parameter) -> kotlin/Unit| { - ^@run lambda@fun (foo: R|ERROR CLASS: No type for parameter|): R|kotlin/Unit| { + public final val x4: R|(kotlin/String) -> kotlin/Unit| = R|/run| kotlin/Unit|>( = run@fun (): R|(kotlin/String) -> kotlin/Unit| { + ^@run lambda@fun (foo: R|kotlin/String|): R|kotlin/Unit| { R|/bar|(R|/foo|) } diff --git a/compiler/fir/resolve/testData/resolve/lambdaPropertyTypeInference.kt b/compiler/fir/resolve/testData/resolve/lambdaPropertyTypeInference.kt index 77d58e48972..8bae96c5e36 100644 --- a/compiler/fir/resolve/testData/resolve/lambdaPropertyTypeInference.kt +++ b/compiler/fir/resolve/testData/resolve/lambdaPropertyTypeInference.kt @@ -26,9 +26,9 @@ fun case1(javaClass: JavaClass?) { validType.checkType { _>() } //ok - invalidType.checkType { _>() } //(!!!) + invalidType.checkType { _>() } //(!!!) - Case1(javaClass).x.checkType { _>() } //(!!!) + Case1(javaClass).x.checkType { _>() } //(!!!) } class Case1(val javaClass: JavaClass?) { @@ -55,9 +55,9 @@ fun case2(kotlinClass: KotlinClass?) { validType.checkType { _>() } //ok - invalidType.checkType { _>() } //(!!!) + invalidType.checkType { _>() } //(!!!) - Case2(kotlinClass).x.checkType { _>() } //(!!!) + Case2(kotlinClass).x.checkType { _>() } //(!!!) } class Case2(val kotlinClass: KotlinClass?) { diff --git a/compiler/fir/resolve/testData/resolve/lambdaPropertyTypeInference.txt b/compiler/fir/resolve/testData/resolve/lambdaPropertyTypeInference.txt index 528aa86de97..212a422d05b 100644 --- a/compiler/fir/resolve/testData/resolve/lambdaPropertyTypeInference.txt +++ b/compiler/fir/resolve/testData/resolve/lambdaPropertyTypeInference.txt @@ -2,7 +2,7 @@ FILE: KotlinClass.kt public final fun case1(javaClass: R|JavaClass?|): R|kotlin/Unit| { lval validType: R|(JavaClass) -> kotlin/Boolean| = when () { !=(R|/javaClass|, Null(null)) -> { - fun (it: R|kotlin/Nothing|): R|kotlin/Boolean| { + fun (it: R|JavaClass|): R|kotlin/Boolean| { ^ ==(R|/it|, R|/javaClass|) } @@ -12,9 +12,9 @@ FILE: KotlinClass.kt } } - lval invalidType: R|(kotlin/Nothing) -> kotlin/Boolean| = when () { + lval invalidType: R|(JavaClass) -> kotlin/Boolean| = when () { !=(R|/javaClass|, Null(null)) -> { - fun (it: R|kotlin/Nothing|): R|kotlin/Boolean| { + fun (it: R|JavaClass|): R|kotlin/Boolean| { ^ ==(R|/it|, R|/javaClass|) } @@ -28,12 +28,12 @@ FILE: KotlinClass.kt this@R|special/anonymous|.R|tests/_checkType/_| kotlin/Boolean|>() } ) - R|/invalidType|.R|tests/_checkType/checkType| kotlin/Boolean|>( = checkType@fun R|tests/_checkType/Inv>|.(): R|kotlin/Unit| { - this@R|special/anonymous|.R|tests/_checkType/_| kotlin/Boolean|>() + R|/invalidType|.R|tests/_checkType/checkType| kotlin/Boolean|>( = checkType@fun R|tests/_checkType/Inv>|.(): R|kotlin/Unit| { + ^ # kotlin/Boolean|>() } ) - R|/Case1.Case1|(R|/javaClass|).R|/Case1.x|.R|tests/_checkType/checkType| kotlin/Boolean|>( = checkType@fun R|tests/_checkType/Inv>|.(): R|kotlin/Unit| { - this@R|special/anonymous|.R|tests/_checkType/_| kotlin/Boolean|>() + R|/Case1.Case1|(R|/javaClass|).R|/Case1.x|.R|tests/_checkType/checkType| kotlin/Boolean|>( = checkType@fun R|tests/_checkType/Inv>|.(): R|kotlin/Unit| { + ^ # kotlin/Boolean|>() } ) } @@ -45,9 +45,9 @@ FILE: KotlinClass.kt public final val javaClass: R|JavaClass?| = R|/javaClass| public get(): R|JavaClass?| - public final val x: R|(kotlin/Nothing) -> kotlin/Boolean| = when () { + public final val x: R|(KotlinClass) -> kotlin/Boolean| = when () { !=(R|/javaClass|, Null(null)) -> { - fun (it: R|kotlin/Nothing|): R|kotlin/Boolean| { + fun (it: R|KotlinClass|): R|kotlin/Boolean| { ^ ==(R|/it|, R|/javaClass|) } @@ -57,7 +57,7 @@ FILE: KotlinClass.kt } } - public get(): R|(kotlin/Nothing) -> kotlin/Boolean| + public get(): R|(KotlinClass) -> kotlin/Boolean| } public final class BooCase1 : R|kotlin/Any| { @@ -95,7 +95,7 @@ FILE: KotlinClass.kt public final fun case2(kotlinClass: R|KotlinClass?|): R|kotlin/Unit| { lval validType: R|(KotlinClass) -> kotlin/Boolean| = when () { !=(R|/kotlinClass|, Null(null)) -> { - fun (it: R|kotlin/Nothing|): R|kotlin/Boolean| { + fun (it: R|KotlinClass|): R|kotlin/Boolean| { ^ ==(R|/it|, R|/kotlinClass|) } @@ -105,9 +105,9 @@ FILE: KotlinClass.kt } } - lval invalidType: R|(kotlin/Nothing) -> kotlin/Boolean| = when () { + lval invalidType: R|(KotlinClass) -> kotlin/Boolean| = when () { !=(R|/kotlinClass|, Null(null)) -> { - fun (it: R|kotlin/Nothing|): R|kotlin/Boolean| { + fun (it: R|KotlinClass|): R|kotlin/Boolean| { ^ ==(R|/it|, R|/kotlinClass|) } @@ -121,12 +121,12 @@ FILE: KotlinClass.kt this@R|special/anonymous|.R|tests/_checkType/_| kotlin/Boolean|>() } ) - R|/invalidType|.R|tests/_checkType/checkType| kotlin/Boolean|>( = checkType@fun R|tests/_checkType/Inv>|.(): R|kotlin/Unit| { - this@R|special/anonymous|.R|tests/_checkType/_| kotlin/Boolean|>() + R|/invalidType|.R|tests/_checkType/checkType| kotlin/Boolean|>( = checkType@fun R|tests/_checkType/Inv>|.(): R|kotlin/Unit| { + ^ # kotlin/Boolean|>() } ) - R|/Case2.Case2|(R|/kotlinClass|).R|/Case2.x|.R|tests/_checkType/checkType| kotlin/Boolean|>( = checkType@fun R|tests/_checkType/Inv>|.(): R|kotlin/Unit| { - this@R|special/anonymous|.R|tests/_checkType/_| kotlin/Boolean|>() + R|/Case2.Case2|(R|/kotlinClass|).R|/Case2.x|.R|tests/_checkType/checkType| kotlin/Boolean|>( = checkType@fun R|tests/_checkType/Inv>|.(): R|kotlin/Unit| { + ^ # kotlin/Boolean|>() } ) } @@ -138,9 +138,9 @@ FILE: KotlinClass.kt public final val kotlinClass: R|KotlinClass?| = R|/kotlinClass| public get(): R|KotlinClass?| - public final val x: R|(kotlin/Nothing) -> kotlin/Boolean| = when () { + public final val x: R|(KotlinClass) -> kotlin/Boolean| = when () { !=(R|/kotlinClass|, Null(null)) -> { - fun (it: R|kotlin/Nothing|): R|kotlin/Boolean| { + fun (it: R|KotlinClass|): R|kotlin/Boolean| { ^ ==(R|/it|, R|/kotlinClass|) } @@ -150,7 +150,7 @@ FILE: KotlinClass.kt } } - public get(): R|(kotlin/Nothing) -> kotlin/Boolean| + public get(): R|(KotlinClass) -> kotlin/Boolean| } public final class BooCase2 : R|kotlin/Any| { diff --git a/compiler/fir/resolve/testData/resolveWithStdlib/delegates/delegateTypeMismatch.kt b/compiler/fir/resolve/testData/resolveWithStdlib/delegates/delegateTypeMismatch.kt index f98bae24319..0524c73e996 100644 --- a/compiler/fir/resolve/testData/resolveWithStdlib/delegates/delegateTypeMismatch.kt +++ b/compiler/fir/resolve/testData/resolveWithStdlib/delegates/delegateTypeMismatch.kt @@ -22,5 +22,5 @@ class A(val isLocked: Boolean) { var classifierNamePolicy: ClassifierNamePolicy by property(ClassifierNamePolicy.SOURCE_CODE_QUALIFIED) // getter has INAPPLICABLE diagnostic, see dump - var typeNormalizer by property<(KotlinType) -> KotlinType>({ it }) + var typeNormalizer by property<(KotlinType) -> KotlinType>({ it }) } diff --git a/compiler/fir/resolve/testData/resolveWithStdlib/delegates/delegateTypeMismatch.txt b/compiler/fir/resolve/testData/resolveWithStdlib/delegates/delegateTypeMismatch.txt index 8771b83360f..f1489c4106f 100644 --- a/compiler/fir/resolve/testData/resolveWithStdlib/delegates/delegateTypeMismatch.txt +++ b/compiler/fir/resolve/testData/resolveWithStdlib/delegates/delegateTypeMismatch.txt @@ -41,15 +41,15 @@ FILE: delegateTypeMismatch.kt D|/A.classifierNamePolicy|.R|FakeOverride|(this@R|/A|, ::R|/A.classifierNamePolicy|, R|/classifierNamePolicy|) } - public final var typeNormalizer: by # KotlinType|>(property@fun (): R|ERROR CLASS: Unresolved name: it| { - ^ # + public final var typeNormalizer: R|(KotlinType) -> KotlinType|by this@R|/A|.R|/A.property| KotlinType|>(property@fun (it: R|KotlinType|): R|KotlinType| { + ^ R|/it| } ) - public get(): { - ^ D|/A.typeNormalizer|.#(this@R|/A|, ::R|/A.typeNormalizer|) + public get(): R|(KotlinType) -> KotlinType| { + ^ D|/A.typeNormalizer|.R|FakeOverride KotlinType|>|(this@R|/A|, ::R|/A.typeNormalizer|) } - public set(: ): R|kotlin/Unit| { - D|/A.typeNormalizer|.#(this@R|/A|, ::R|/A.typeNormalizer|, R|/typeNormalizer|) + public set(: R|(KotlinType) -> KotlinType|): R|kotlin/Unit| { + D|/A.typeNormalizer|.R|FakeOverride|(this@R|/A|, ::R|/A.typeNormalizer|, R|/typeNormalizer|) } } diff --git a/compiler/fir/resolve/testData/resolveWithStdlib/delegates/propertyWithFunctionalType.kt b/compiler/fir/resolve/testData/resolveWithStdlib/delegates/propertyWithFunctionalType.kt new file mode 100644 index 00000000000..fcae15dc03f --- /dev/null +++ b/compiler/fir/resolve/testData/resolveWithStdlib/delegates/propertyWithFunctionalType.kt @@ -0,0 +1,12 @@ +// ISSUE: KT-37304 + +import kotlin.properties.ReadWriteProperty + +interface B + +class A { + private fun property(initialValue: T): ReadWriteProperty = null!! + + var conventer by property<(B) -> B>({ it }) + var conventerWithExpectedType: (B) -> B by property({ it }) +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolveWithStdlib/delegates/propertyWithFunctionalType.txt b/compiler/fir/resolve/testData/resolveWithStdlib/delegates/propertyWithFunctionalType.txt new file mode 100644 index 00000000000..ae321287357 --- /dev/null +++ b/compiler/fir/resolve/testData/resolveWithStdlib/delegates/propertyWithFunctionalType.txt @@ -0,0 +1,35 @@ +FILE: propertyWithFunctionalType.kt + public abstract interface B : R|kotlin/Any| { + } + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + private final fun property(initialValue: R|T|): R|kotlin/properties/ReadWriteProperty| { + ^property Null(null)!! + } + + public final var conventer: R|(B) -> B|by this@R|/A|.R|/A.property| B|>(property@fun (it: R|B|): R|B| { + ^ R|/it| + } + ) + public get(): R|(B) -> B| { + ^ D|/A.conventer|.R|FakeOverride B|>|(this@R|/A|, ::R|/A.conventer|) + } + public set(: R|(B) -> B|): R|kotlin/Unit| { + D|/A.conventer|.R|FakeOverride|(this@R|/A|, ::R|/A.conventer|, R|/conventer|) + } + + public final var conventerWithExpectedType: R|(B) -> B|by this@R|/A|.R|/A.property| B|>(property@fun (it: R|B|): R|B| { + ^ R|/it| + } + ) + public get(): R|(B) -> B| { + ^ D|/A.conventerWithExpectedType|.R|FakeOverride B|>|(this@R|/A|, ::R|/A.conventerWithExpectedType|) + } + public set(: R|(B) -> B|): R|kotlin/Unit| { + D|/A.conventerWithExpectedType|.R|FakeOverride|(this@R|/A|, ::R|/A.conventerWithExpectedType|, R|/conventerWithExpectedType|) + } + + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java index 4588a0dae31..6acac89b1c8 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java @@ -519,6 +519,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic runTest("compiler/fir/resolve/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.kt"); } + @TestMetadata("propertyWithFunctionalType.kt") + public void testPropertyWithFunctionalType() throws Exception { + runTest("compiler/fir/resolve/testData/resolveWithStdlib/delegates/propertyWithFunctionalType.kt"); + } + @TestMetadata("simpleDelegateProvider.kt") public void testSimpleDelegateProvider() throws Exception { runTest("compiler/fir/resolve/testData/resolveWithStdlib/delegates/simpleDelegateProvider.kt"); diff --git a/compiler/testData/codegen/box/regressions/functionLiteralAsLastExpressionInBlock.kt b/compiler/testData/codegen/box/regressions/functionLiteralAsLastExpressionInBlock.kt index f6bad7bccd0..13ed03338d2 100644 --- a/compiler/testData/codegen/box/regressions/functionLiteralAsLastExpressionInBlock.kt +++ b/compiler/testData/codegen/box/regressions/functionLiteralAsLastExpressionInBlock.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { val p: (String) -> Boolean = if (true) { { true } diff --git a/compiler/testData/codegen/box/regressions/lambdaAsLastExpressionInLambda.kt b/compiler/testData/codegen/box/regressions/lambdaAsLastExpressionInLambda.kt index b9dfbc13167..05336badb47 100644 --- a/compiler/testData/codegen/box/regressions/lambdaAsLastExpressionInLambda.kt +++ b/compiler/testData/codegen/box/regressions/lambdaAsLastExpressionInLambda.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR val foo: ((String) -> String) = run { { it } } diff --git a/compiler/testData/diagnostics/tests/inference/constraints/returnLambdaFromLambda.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/returnLambdaFromLambda.fir.kt index 760463301bc..0f100c7b735 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/returnLambdaFromLambda.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/constraints/returnLambdaFromLambda.fir.kt @@ -6,7 +6,7 @@ fun testLambda() { if (x is String) return@myRun { it -> x.length + it } if (x !is Int) return@myRun { it -> it } - { it -> x + it } + { it -> x + it } } val twoLambda: (Int) -> Int = myRun { diff --git a/compiler/testData/diagnostics/tests/inference/kt3184.fir.kt b/compiler/testData/diagnostics/tests/inference/kt3184.fir.kt deleted file mode 100644 index c0565f6c952..00000000000 --- a/compiler/testData/diagnostics/tests/inference/kt3184.fir.kt +++ /dev/null @@ -1,26 +0,0 @@ -//KT-3184 Type inference seems partially broken -package a - -import java.util.HashMap - -private fun test(value: T, extf: String.(value: T)->Unit) { - "".extf(value) -} - -fun main() { - test(1, {value -> println(value)}) -} - -fun tests() { - val dict = HashMap Unit>() - dict["0"] = { str -> println(str) } - dict["1"] = { println(it) } - - dict.set("1", { println(it) }) - dict["1"] = { r -> println(r) } -} - -// from standard library -operator fun MutableMap.set(key : K, value : V) : V? = this.put(key, value) - -fun println(message : Any?) = System.out.println(message) \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt3184.kt b/compiler/testData/diagnostics/tests/inference/kt3184.kt index 227942a690a..95846be653f 100644 --- a/compiler/testData/diagnostics/tests/inference/kt3184.kt +++ b/compiler/testData/diagnostics/tests/inference/kt3184.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL //KT-3184 Type inference seems partially broken package a diff --git a/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitution.fir.kt b/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitution.fir.kt deleted file mode 100644 index 9ff15b91a24..00000000000 --- a/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitution.fir.kt +++ /dev/null @@ -1,37 +0,0 @@ -// !LANGUAGE: +NewInference -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER - -class B { - class Builder -} - -typealias ApplyRestrictions = B.Builder.() -> B.Builder - -fun applyRestrictions1(): ApplyRestrictions = TODO() -fun applyRestrictions2() = applyRestrictions1() -fun applyRestrictions3(e: K) = applyRestrictions1() - -fun buildB() { - val a1 = applyRestrictions1() - val a2 = applyRestrictions2() - val a3 = applyRestrictions3("foo") - - B.Builder().a1() - B.Builder().a2() - B.Builder().a3() -} - -// additional example from #KT-34820 - -class R -class P - -typealias F = R.(P) -> Unit - -fun guess(): F? = TODO() -fun consume(f: F) {} - -fun problem() { - val p = guess() - consume(p ?: {}) -} diff --git a/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitution.kt b/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitution.kt index 0c877efeb43..2576deba9b4 100644 --- a/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitution.kt +++ b/compiler/testData/diagnostics/tests/inference/substitutions/kt32189returnTypeWithTypealiasSubtitution.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +NewInference // !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER diff --git a/compiler/testData/diagnostics/tests/regressions/kt10843.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt10843.fir.kt index d8b434aa4a4..c34a25f506f 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt10843.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt10843.fir.kt @@ -3,6 +3,6 @@ // See EA-76890 / KT-10843: NPE during analysis fun lambda(x : Int?) = x?.let l { y -> - if (y > 0) return@l x + if (y > 0) return@l x y }!! diff --git a/compiler/testData/diagnostics/tests/regressions/kt30245.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt30245.fir.kt index 5ebafaa1404..46fb6b9a25c 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt30245.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt30245.fir.kt @@ -38,7 +38,7 @@ class W4(val f: L2) { fun test1() { // to extension lambda 0 val w10 = W1 { this } // oi+ ni+ val i10: E0 = id { this } // o1- ni+ - val j10 = id { this } // oi+ ni+ + val j10 = id { this } // oi+ ni+ val f10 = W1(fun Int.(): Int = this) // oi+ ni+ val g10: E0 = id(fun Int.(): Int = this) // oi+ ni+ @@ -46,7 +46,7 @@ fun test1() { // to extension lambda 0 val i11: E0 = id { i: Int -> i } // o1+ ni+ val w12 = W1 { i -> i } // oi- ni- val i12: E0 = id { i -> i } // oi- ni- - val j12 = id { i -> i } // oi- ni- + val j12 = id { i -> i } // oi- ni- // yet unsupported cases - considering lambdas as extension ones unconditionally // val w13 = W1 { it } // this or it: oi- ni- @@ -79,7 +79,7 @@ fun test2() { // to extension lambda 1 // val i27: E1 = id { i, s: String -> i + s.length } // overload oi- ni- val w28 = W2 { i: Int, s -> i + s.length } // oi- ni- - val i28: E1 = id { i: Int, s -> i + s.length } // oi- ni- + val i28: E1 = id { i: Int, s -> i + s.length } // oi- ni- val w29 = W2 { i: Int, s: String -> i + s.length } // oi- ni- val i29: E1 = id { i: Int, s: String -> i + s.length } // oi+ ni+ @@ -92,8 +92,8 @@ fun test3() { // to non-extension lambda 1 val w30 = W3 { i -> i } // oi+ ni+ val i30: L1 = id { i -> i } // oi+ ni+ val w31 = W3 { it } // oi+ ni+ - val i31: L1 = id { it } // oi- ni+ - val j31 = id { it } // oi+ ni+ + val i31: L1 = id { it } // oi- ni+ + val j31 = id { it } // oi+ ni+ // yet unsupported cases - considering lambdas as extension ones unconditionally // val w32 = W3 { this } // this or it: oi- ni- diff --git a/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralWithId.fir.kt b/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralWithId.fir.kt deleted file mode 100644 index cf4402b7539..00000000000 --- a/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralWithId.fir.kt +++ /dev/null @@ -1,32 +0,0 @@ -//If this test hangs, it means something is broken. -object A { - val iii = 42 -} - -//inappropriate but participating in resolve functions -fun foo(s: String, a: Any) = s + a -fun foo(a: Any) = a -fun foo(i: Int) = i -fun foo(a: Any, i: Int, f: ()-> Int) = "$a$i${f()}" -fun foo(f: (Int)->Int, i: Int) = f(i) -fun foo(f: (String)->Int, s: String) = f(s) -fun foo(f: (Any)->Int, a: Any) = f(a) -fun foo(s: String, f: (String, String)->Int) = f(s, s) -//appropriate function -fun foo(i: Int, f: (Int)->Int) = f(i) - -fun id(t: T) = t - -fun test() { - foo(1, id { x1 -> - foo(2, id { x2 -> - foo(3, id { x3 -> - foo(4, id { x4 -> - foo(5, id { x5 -> - x1 + x2 + x3 + x4 + x5 + A.iii - }) - }) - }) - }) - }) -} diff --git a/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralWithId.kt b/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralWithId.kt index 93a230cabef..71b999b29a2 100644 --- a/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralWithId.kt +++ b/compiler/testData/diagnostics/tests/resolve/resolveWithFunctionLiteralWithId.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL //If this test hangs, it means something is broken. object A { val iii = 42 diff --git a/compiler/testData/diagnostics/tests/resolve/resolveWithSpecifiedFunctionLiteralWithId.fir.kt b/compiler/testData/diagnostics/tests/resolve/resolveWithSpecifiedFunctionLiteralWithId.fir.kt index 67b4400b312..c7a162d39fc 100644 --- a/compiler/testData/diagnostics/tests/resolve/resolveWithSpecifiedFunctionLiteralWithId.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/resolveWithSpecifiedFunctionLiteralWithId.fir.kt @@ -22,11 +22,11 @@ fun foo(i: Int, f: (Int) -> Int) = f(i) fun id(t: T) = t fun test() { - foo(1, id(fun(x1: Int) = - foo(2, id(fun(x2: Int) = - foo(3, id(fun(x3: Int) = - foo(4, id(fun(x4: Int) = - foo(5, id(fun(x5: Int) = + foo(1, id(fun(x1: Int) = + foo(2, id(fun(x2: Int) = + foo(3, id(fun(x3: Int) = + foo(4, id(fun(x4: Int) = + foo(5, id(fun(x5: Int) = x1 + x2 + x3 + x4 + x5 + A.iii )) ))