@@ -3195,6 +3195,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
31953195 val superCls = cls.superClass
31963196 superCls.exists && superCls.asClass.baseClasses.contains(m.symbol.owner)
31973197
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+
31983214 def givenImpl (mbr : TermRef ): ValDef =
31993215 val dcl = mbr.symbol
32003216 val target = dcl.info.asSeenFrom(cls.thisType, dcl.owner)
@@ -3203,29 +3219,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
32033219 val paramScope = newScopeWith(usingParamAccessors* )
32043220 val searchCtx = ctx.outer.fresh.setScope(paramScope)
32053221
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,
32193224 where = i " inferring the implementation of the deferred ${dcl.showLocated}"
32203225 )(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 _ =>
32293232
32303233 val impl = dcl.copy(cls,
32313234 flags = dcl.flags &~ (HasDefault | Deferred ) | Final | Override ,
@@ -3243,15 +3246,13 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
32433246
32443247 if cls.is(Trait ) || ctx.isAfterTyper then body
32453248 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)
32553256 end implementDeferredGivens
32563257
32573258 ensureCorrectSuperClass()
0 commit comments