diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt index 127b6fe047b..5456bbdb1d2 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/MethodInliner.kt @@ -859,9 +859,20 @@ class MethodInliner( needReification: Boolean, capturesAnonymousObjectThatMustBeRegenerated: Boolean ): AnonymousObjectTransformationInfo { - + // In objects inside non-default lambdas, all reified type parameters are free (not from the function + // we're inlining into) so there's nothing to reify: + // + // inline fun f(x: () -> KClass = { { T::class }() }) = x() + // fun a() = f() + // fun b() = f { { Int::class }() } // non-default lambda + // inline fun c() = f { { V::class }() } + // + // -- in a(), the default lambda captures T so a regeneration is needed; but in b() and c(), the non-default + // lambda cannot possibly reference it, while V is not yet bound so regenerating the object while inlining + // the lambda into f() is pointless. + val inNonDefaultLambda = inliningContext.isInliningLambda && inliningContext.lambdaInfo !is DefaultLambda val info = AnonymousObjectTransformationInfo( - anonymousType, needReification, lambdaMapping, + anonymousType, needReification && !inNonDefaultLambda, lambdaMapping, inliningContext.classRegeneration, isAlreadyRegenerated(anonymousType), desc,