@@ -110,27 +110,26 @@ class KoinDSLTransformer(
110110 private val currentDefinitionCall: Name ? get() = transformContext.definitionCall
111111
112112 override fun visitFunctionExpression (expression : IrFunctionExpression ): IrExpression {
113- val previousContext = transformContext
114- transformContext = transformContext.copy(lambda = expression.function)
115- val result = super .visitFunctionExpression(expression)
116- // Preserve qualifier propagation from inner create(::T) across lambda boundary
117- val innerQualifier = transformContext.createQualifier
118- val innerReturnClass = transformContext.createReturnClass
119- transformContext = previousContext
120- if (innerQualifier != null ) {
121- transformContext = transformContext.copy(
122- createQualifier = innerQualifier,
123- createReturnClass = innerReturnClass
124- )
113+ return withContext(transformContext.copy(lambda = expression.function)) {
114+ super .visitFunctionExpression(expression)
125115 }
126- return result
127116 }
128117
129118 override fun visitFunction (declaration : IrFunction ): IrStatement {
119+ return withContext(transformContext.copy(function = declaration)) {
120+ super .visitFunction(declaration)
121+ }
122+ }
123+
124+ /* *
125+ * Run [block] with a scoped [TransformContext], restoring the previous context afterward.
126+ * Qualifier propagation from inner create(::T) is preserved across the boundary so that
127+ * the enclosing definition call (single/factory/etc.) can pick it up.
128+ */
129+ private inline fun <T > withContext (newContext : TransformContext , block : () -> T ): T {
130130 val previousContext = transformContext
131- transformContext = transformContext.copy(function = declaration)
132- val result = super .visitFunction(declaration)
133- // Preserve qualifier propagation from inner create(::T) across function boundary
131+ transformContext = newContext
132+ val result = block()
134133 val innerQualifier = transformContext.createQualifier
135134 val innerReturnClass = transformContext.createReturnClass
136135 transformContext = previousContext
0 commit comments