@@ -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.
@@ -1499,6 +1500,7 @@ class Namer { typer: Typer =>
14991500 /** The type signature of a ClassDef with given symbol */
15001501 override def completeInCreationContext (denot : SymDenotation ): Unit = {
15011502 val parents = impl.parents
1503+ val parentRefinements = new mutable.LinkedHashMap [Name , Type ]
15021504
15031505 /* The type of a parent constructor. Types constructor arguments
15041506 * only if parent type contains uninstantiated type parameters.
@@ -1550,8 +1552,13 @@ class Namer { typer: Typer =>
15501552 val ptype = parentType(parent)(using completerCtx.superCallContext).dealiasKeepAnnots
15511553 if (cls.isRefinementClass) ptype
15521554 else {
1553- val pt = checkClassType(ptype, parent.srcPos,
1554- traitReq = parent ne parents.head, stablePrefixReq = true )
1555+ val pt = checkClassType(
1556+ if Feature .enabled(modularity)
1557+ then ptype.separateRefinements(cls, parentRefinements)
1558+ else ptype,
1559+ parent.srcPos,
1560+ traitReq = parent ne parents.head,
1561+ stablePrefixReq = true )
15551562 if (pt.derivesFrom(cls)) {
15561563 val addendum = parent match {
15571564 case Select (qual : Super , _) if Feature .migrateTo3 =>
@@ -1578,6 +1585,21 @@ class Namer { typer: Typer =>
15781585 }
15791586 }
15801587
1588+ /** Enter all parent refinements as public class members, unless a definition
1589+ * with the same name already exists in the class.
1590+ */
1591+ def enterParentRefinementSyms (refinements : List [(Name , Type )]) =
1592+ val refinedSyms = mutable.ListBuffer [Symbol ]()
1593+ for (name, tp) <- refinements do
1594+ if decls.lookupEntry(name) == null then
1595+ val flags = tp match
1596+ case tp : MethodOrPoly => Method | Synthetic | Deferred
1597+ case _ => Synthetic | Deferred
1598+ refinedSyms += newSymbol(cls, name, flags, tp, coord = original.rhs.span.startPos).entered
1599+ if refinedSyms.nonEmpty then
1600+ typr.println(i " parent refinement symbols: ${refinedSyms.toList}" )
1601+ original.pushAttachment(ParentRefinements , refinedSyms.toList)
1602+
15811603 /** If `parents` contains references to traits that have supertraits with implicit parameters
15821604 * add those supertraits in linearization order unless they are already covered by other
15831605 * parent types. For instance, in
@@ -1646,6 +1668,7 @@ class Namer { typer: Typer =>
16461668 cls.invalidateMemberCaches() // we might have checked for a member when parents were not known yet.
16471669 cls.setNoInitsFlags(parentsKind(parents), untpd.bodyKind(rest))
16481670 cls.setStableConstructor()
1671+ enterParentRefinementSyms(parentRefinements.toList)
16491672 processExports(using localCtx)
16501673 defn.patchStdLibClass(cls)
16511674 addConstructorProxies(cls)
0 commit comments