@@ -3195,6 +3195,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3195
3195
val superCls = cls.superClass
3196
3196
superCls.exists && superCls.asClass.baseClasses.contains(m.symbol.owner)
3197
3197
3198
+ // Before losing the reference to ctx.owner
3199
+ // when calling implicitArgTree with searchCtx,
3200
+ // let's store ctx.owner as the fallback "responsibleForImports"
3201
+ // in DependencyRecorder. That way, if we end up recording any dependencies
3202
+ // we use ctx.owner as the "fromClass" rather than emitting a warning
3203
+ // (because ctx.compilationUnit.tpdTree is still EmptyTree during typer).
3204
+ // For example, to record mirror dependencies, see i23049.
3205
+ inline def withOwnerResponsibleForImports [A ](inline op : A ): A =
3206
+ val depRecorder = ctx.compilationUnit.depRecorder
3207
+ val responsibleForImports = depRecorder._responsibleForImports
3208
+ if responsibleForImports == null then
3209
+ depRecorder._responsibleForImports = ctx.owner
3210
+ op.tap: _ =>
3211
+ if responsibleForImports == null then
3212
+ depRecorder._responsibleForImports = null
3213
+
3198
3214
def givenImpl (mbr : TermRef ): ValDef =
3199
3215
val dcl = mbr.symbol
3200
3216
val target = dcl.info.asSeenFrom(cls.thisType, dcl.owner)
@@ -3203,29 +3219,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3203
3219
val paramScope = newScopeWith(usingParamAccessors* )
3204
3220
val searchCtx = ctx.outer.fresh.setScope(paramScope)
3205
3221
3206
- // Before losing the reference to ctx.owner
3207
- // when calling implicitArgTree with searchCtx,
3208
- // let's store ctx.owner as the fallback "responsibleForImports"
3209
- // in DependencyRecorder. That way, if we end up recording any dependencies
3210
- // we use ctx.owner as the "fromClass" rather than emitting a warning
3211
- // (because ctx.compilationUnit.tpdTree is still EmptyTree during typer).
3212
- // For example, to record mirror dependencies, see i23049.
3213
- val depRecorder = ctx.compilationUnit.depRecorder
3214
- val responsibleForImports = depRecorder._responsibleForImports
3215
- if responsibleForImports == null then
3216
- depRecorder._responsibleForImports = ctx.owner
3217
-
3218
- val rhs = implicitArgTree(target, cdef.span,
3222
+ val rhs = withOwnerResponsibleForImports :
3223
+ implicitArgTree(target, cdef.span,
3219
3224
where = i " inferring the implementation of the deferred ${dcl.showLocated}"
3220
3225
)(using searchCtx)
3221
- val resolvedHere =
3222
- rhs.tpe match
3223
- case tp : NamedType => (tp.prefix.typeSymbol eq cls) && tp.name == mbr.name && ! tp.typeSymbol.is(Method )
3224
- case _ => false
3225
- if resolvedHere then failFor(mbr, " the result is self-recursive" )
3226
-
3227
- if responsibleForImports == null then
3228
- depRecorder._responsibleForImports = null
3226
+ .tap:
3227
+ _.tpe match
3228
+ case tp : NamedType =>
3229
+ val resolvedHere = tp.prefix.typeSymbol == cls && tp.name == mbr.name && ! tp.typeSymbol.is(Method )
3230
+ if resolvedHere then failFor(mbr, " the result is self-recursive" )
3231
+ case _ =>
3229
3232
3230
3233
val impl = dcl.copy(cls,
3231
3234
flags = dcl.flags &~ (HasDefault | Deferred ) | Final | Override ,
@@ -3243,15 +3246,13 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3243
3246
3244
3247
if cls.is(Trait ) || ctx.isAfterTyper then body
3245
3248
else
3246
- val givenImpls =
3247
- cls.thisType.implicitMembers
3248
- // .showing(i"impl def givens for $cls/$result")
3249
- .filter(_.symbol.isAllOf(DeferredGivenFlags , butNot = Param ))
3250
- .filter(! willBeImplementedInParentClass(_)) // only implement the given in the topmost class
3251
- // .showing(i"impl def filtered givens for $cls/$result")
3252
- .filter(isGivenValue)
3253
- .map(givenImpl)
3254
- body ++ givenImpls
3249
+ body ++ cls.thisType.implicitMembers
3250
+ // .showing(i"impl def givens for $cls/$result")
3251
+ .filter(_.symbol.isAllOf(DeferredGivenFlags , butNot = Param ))
3252
+ .filter(! willBeImplementedInParentClass(_)) // only implement the given in the topmost class
3253
+ // .showing(i"impl def filtered givens for $cls/$result")
3254
+ .filter(isGivenValue)
3255
+ .map(givenImpl)
3255
3256
end implementDeferredGivens
3256
3257
3257
3258
ensureCorrectSuperClass()
0 commit comments