@@ -55,11 +55,12 @@ class Namer { typer: Typer =>
55
55
56
56
import untpd .*
57
57
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
63
64
// was `val Deriver`, but that gave shadowing problems with constructor proxies
64
65
65
66
/** A partial map from unexpanded member and pattern defs and to their expansions.
@@ -1515,6 +1516,7 @@ class Namer { typer: Typer =>
1515
1516
/** The type signature of a ClassDef with given symbol */
1516
1517
override def completeInCreationContext (denot : SymDenotation ): Unit = {
1517
1518
val parents = impl.parents
1519
+ val parentRefinements = new mutable.LinkedHashMap [Name , Type ]
1518
1520
1519
1521
/* The type of a parent constructor. Types constructor arguments
1520
1522
* only if parent type contains uninstantiated type parameters.
@@ -1569,8 +1571,13 @@ class Namer { typer: Typer =>
1569
1571
val ptype = parentType(parent)(using completerCtx.superCallContext).dealiasKeepAnnots
1570
1572
if (cls.isRefinementClass) ptype
1571
1573
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)
1574
1581
if (pt.derivesFrom(cls)) {
1575
1582
val addendum = parent match {
1576
1583
case Select (qual : Super , _) if Feature .migrateTo3 =>
@@ -1597,6 +1604,21 @@ class Namer { typer: Typer =>
1597
1604
}
1598
1605
}
1599
1606
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
+
1600
1622
/** If `parents` contains references to traits that have supertraits with implicit parameters
1601
1623
* add those supertraits in linearization order unless they are already covered by other
1602
1624
* parent types. For instance, in
@@ -1667,6 +1689,7 @@ class Namer { typer: Typer =>
1667
1689
cls.invalidateMemberCaches() // we might have checked for a member when parents were not known yet.
1668
1690
cls.setNoInitsFlags(parentsKind(parents), untpd.bodyKind(rest))
1669
1691
cls.setStableConstructor()
1692
+ enterParentRefinementSyms(parentRefinements.toList)
1670
1693
processExports(using localCtx)
1671
1694
defn.patchStdLibClass(cls)
1672
1695
addConstructorProxies(cls)
0 commit comments