@@ -55,11 +55,12 @@ class Namer { typer: Typer =>
5555
5656 import untpd .*
5757
58- val TypedAhead : Property .Key [tpd.Tree ] = new Property .Key
59- val ExpandedTree : Property .Key [untpd.Tree ] = new Property .Key
60- val ExportForwarders : Property .Key [List [tpd.MemberDef ]] = new Property .Key
61- val SymOfTree : Property .Key [Symbol ] = new Property .Key
62- val AttachedDeriver : Property .Key [Deriver ] = new Property .Key
58+ val TypedAhead : Property .Key [tpd.Tree ] = new Property .Key
59+ val ExpandedTree : Property .Key [untpd.Tree ] = new Property .Key
60+ val ExportForwarders : Property .Key [List [tpd.MemberDef ]] = new Property .Key
61+ val ParentRefinements : Property .Key [List [Symbol ]] = new Property .Key
62+ val SymOfTree : Property .Key [Symbol ] = new Property .Key
63+ val AttachedDeriver : Property .Key [Deriver ] = new Property .Key
6364 // was `val Deriver`, but that gave shadowing problems with constructor proxies
6465
6566 /** A partial map from unexpanded member and pattern defs and to their expansions.
@@ -1515,6 +1516,7 @@ class Namer { typer: Typer =>
15151516 /** The type signature of a ClassDef with given symbol */
15161517 override def completeInCreationContext (denot : SymDenotation ): Unit = {
15171518 val parents = impl.parents
1519+ val parentRefinements = new mutable.LinkedHashMap [Name , Type ]
15181520
15191521 /* The type of a parent constructor. Types constructor arguments
15201522 * only if parent type contains uninstantiated type parameters.
@@ -1569,8 +1571,13 @@ class Namer { typer: Typer =>
15691571 val ptype = parentType(parent)(using completerCtx.superCallContext).dealiasKeepAnnots
15701572 if (cls.isRefinementClass) ptype
15711573 else {
1572- val pt = checkClassType(ptype, parent.srcPos,
1573- traitReq = parent ne parents.head, stablePrefixReq = ! isJava)
1574+ val pt = checkClassType(
1575+ if Feature .enabled(modularity)
1576+ then ptype.separateRefinements(cls, parentRefinements)
1577+ else ptype,
1578+ parent.srcPos,
1579+ traitReq = parent ne parents.head,
1580+ stablePrefixReq = ! isJava)
15741581 if (pt.derivesFrom(cls)) {
15751582 val addendum = parent match {
15761583 case Select (qual : Super , _) if Feature .migrateTo3 =>
@@ -1597,6 +1604,21 @@ class Namer { typer: Typer =>
15971604 }
15981605 }
15991606
1607+ /** Enter all parent refinements as public class members, unless a definition
1608+ * with the same name already exists in the class.
1609+ */
1610+ def enterParentRefinementSyms (refinements : List [(Name , Type )]) =
1611+ val refinedSyms = mutable.ListBuffer [Symbol ]()
1612+ for (name, tp) <- refinements do
1613+ if decls.lookupEntry(name) == null then
1614+ val flags = tp match
1615+ case tp : MethodOrPoly => Method | Synthetic | Deferred
1616+ case _ => Synthetic | Deferred
1617+ refinedSyms += newSymbol(cls, name, flags, tp, coord = original.rhs.span.startPos).entered
1618+ if refinedSyms.nonEmpty then
1619+ typr.println(i " parent refinement symbols: ${refinedSyms.toList}" )
1620+ original.pushAttachment(ParentRefinements , refinedSyms.toList)
1621+
16001622 /** If `parents` contains references to traits that have supertraits with implicit parameters
16011623 * add those supertraits in linearization order unless they are already covered by other
16021624 * parent types. For instance, in
@@ -1667,6 +1689,7 @@ class Namer { typer: Typer =>
16671689 cls.invalidateMemberCaches() // we might have checked for a member when parents were not known yet.
16681690 cls.setNoInitsFlags(parentsKind(parents), untpd.bodyKind(rest))
16691691 cls.setStableConstructor()
1692+ enterParentRefinementSyms(parentRefinements.toList)
16701693 processExports(using localCtx)
16711694 defn.patchStdLibClass(cls)
16721695 addConstructorProxies(cls)
0 commit comments