@@ -3249,6 +3249,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3249
3249
val superCls = cls.superClass
3250
3250
superCls.exists && superCls.asClass.baseClasses.contains(m.symbol.owner)
3251
3251
3252
+ // Before losing the reference to ctx.owner
3253
+ // when calling implicitArgTree with searchCtx,
3254
+ // let's store ctx.owner as the fallback "responsibleForImports"
3255
+ // in DependencyRecorder. That way, if we end up recording any dependencies
3256
+ // we use ctx.owner as the "fromClass" rather than emitting a warning
3257
+ // (because ctx.compilationUnit.tpdTree is still EmptyTree during typer).
3258
+ // For example, to record mirror dependencies, see i23049.
3259
+ inline def withOwnerResponsibleForImports [A ](inline op : A ): A =
3260
+ val depRecorder = ctx.compilationUnit.depRecorder
3261
+ val responsibleForImports = depRecorder._responsibleForImports
3262
+ if responsibleForImports == null then
3263
+ depRecorder._responsibleForImports = ctx.owner
3264
+ op.tap: _ =>
3265
+ if responsibleForImports == null then
3266
+ depRecorder._responsibleForImports = null
3267
+
3252
3268
def givenImpl (mbr : TermRef ): ValDef =
3253
3269
val dcl = mbr.symbol
3254
3270
val target = dcl.info.asSeenFrom(cls.thisType, dcl.owner)
@@ -3257,29 +3273,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3257
3273
val paramScope = newScopeWith(usingParamAccessors* )
3258
3274
val searchCtx = ctx.outer.fresh.setScope(paramScope)
3259
3275
3260
- // Before losing the reference to ctx.owner
3261
- // when calling implicitArgTree with searchCtx,
3262
- // let's store ctx.owner as the fallback "responsibleForImports"
3263
- // in DependencyRecorder. That way, if we end up recording any dependencies
3264
- // we use ctx.owner as the "fromClass" rather than emitting a warning
3265
- // (because ctx.compilationUnit.tpdTree is still EmptyTree during typer).
3266
- // For example, to record mirror dependencies, see i23049.
3267
- val depRecorder = ctx.compilationUnit.depRecorder
3268
- val responsibleForImports = depRecorder._responsibleForImports
3269
- if responsibleForImports == null then
3270
- depRecorder._responsibleForImports = ctx.owner
3271
-
3272
- val rhs = implicitArgTree(target, cdef.span,
3276
+ val rhs = withOwnerResponsibleForImports :
3277
+ implicitArgTree(target, cdef.span,
3273
3278
where = i " inferring the implementation of the deferred ${dcl.showLocated}"
3274
3279
)(using searchCtx)
3275
- val resolvedHere =
3276
- rhs.tpe match
3277
- case tp : NamedType => (tp.prefix.typeSymbol eq cls) && tp.name == mbr.name && ! tp.typeSymbol.is(Method )
3278
- case _ => false
3279
- if resolvedHere then failFor(mbr, " the result is self-recursive" )
3280
-
3281
- if responsibleForImports == null then
3282
- depRecorder._responsibleForImports = null
3280
+ .tap:
3281
+ _.tpe match
3282
+ case tp : NamedType =>
3283
+ val resolvedHere = tp.prefix.typeSymbol == cls && tp.name == mbr.name && ! tp.typeSymbol.is(Method )
3284
+ if resolvedHere then failFor(mbr, " the result is self-recursive" )
3285
+ case _ =>
3283
3286
3284
3287
val impl = dcl.copy(cls,
3285
3288
flags = dcl.flags &~ (HasDefault | Deferred ) | Final | Override ,
@@ -3297,15 +3300,13 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3297
3300
3298
3301
if cls.is(Trait ) || ctx.isAfterTyper then body
3299
3302
else
3300
- val givenImpls =
3301
- cls.thisType.implicitMembers
3302
- // .showing(i"impl def givens for $cls/$result")
3303
- .filter(_.symbol.isAllOf(DeferredGivenFlags , butNot = Param ))
3304
- .filter(! willBeImplementedInParentClass(_)) // only implement the given in the topmost class
3305
- // .showing(i"impl def filtered givens for $cls/$result")
3306
- .filter(isGivenValue)
3307
- .map(givenImpl)
3308
- body ++ givenImpls
3303
+ body ++ cls.thisType.implicitMembers
3304
+ // .showing(i"impl def givens for $cls/$result")
3305
+ .filter(_.symbol.isAllOf(DeferredGivenFlags , butNot = Param ))
3306
+ .filter(! willBeImplementedInParentClass(_)) // only implement the given in the topmost class
3307
+ // .showing(i"impl def filtered givens for $cls/$result")
3308
+ .filter(isGivenValue)
3309
+ .map(givenImpl)
3309
3310
end implementDeferredGivens
3310
3311
3311
3312
ensureCorrectSuperClass()
0 commit comments