@@ -3249,6 +3249,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
32493249 val superCls = cls.superClass
32503250 superCls.exists && superCls.asClass.baseClasses.contains(m.symbol.owner)
32513251
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+
32523268 def givenImpl (mbr : TermRef ): ValDef =
32533269 val dcl = mbr.symbol
32543270 val target = dcl.info.asSeenFrom(cls.thisType, dcl.owner)
@@ -3257,29 +3273,16 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
32573273 val paramScope = newScopeWith(usingParamAccessors* )
32583274 val searchCtx = ctx.outer.fresh.setScope(paramScope)
32593275
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,
32733278 where = i " inferring the implementation of the deferred ${dcl.showLocated}"
32743279 )(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 _ =>
32833286
32843287 val impl = dcl.copy(cls,
32853288 flags = dcl.flags &~ (HasDefault | Deferred ) | Final | Override ,
@@ -3297,15 +3300,13 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
32973300
32983301 if cls.is(Trait ) || ctx.isAfterTyper then body
32993302 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)
33093310 end implementDeferredGivens
33103311
33113312 ensureCorrectSuperClass()
0 commit comments