@@ -54,11 +54,12 @@ class Namer { typer: Typer =>
54
54
55
55
import untpd .*
56
56
57
- val TypedAhead : Property .Key [tpd.Tree ] = new Property .Key
58
- val ExpandedTree : Property .Key [untpd.Tree ] = new Property .Key
59
- val ExportForwarders : Property .Key [List [tpd.MemberDef ]] = new Property .Key
60
- val SymOfTree : Property .Key [Symbol ] = new Property .Key
61
- val AttachedDeriver : Property .Key [Deriver ] = new Property .Key
57
+ val TypedAhead : Property .Key [tpd.Tree ] = new Property .Key
58
+ val ExpandedTree : Property .Key [untpd.Tree ] = new Property .Key
59
+ val ExportForwarders : Property .Key [List [tpd.MemberDef ]] = new Property .Key
60
+ val ParentRefinements : Property .Key [List [Symbol ]] = new Property .Key
61
+ val SymOfTree : Property .Key [Symbol ] = new Property .Key
62
+ val AttachedDeriver : Property .Key [Deriver ] = new Property .Key
62
63
// was `val Deriver`, but that gave shadowing problems with constructor proxies
63
64
64
65
/** A partial map from unexpanded member and pattern defs and to their expansions.
@@ -1485,6 +1486,7 @@ class Namer { typer: Typer =>
1485
1486
/** The type signature of a ClassDef with given symbol */
1486
1487
override def completeInCreationContext (denot : SymDenotation ): Unit = {
1487
1488
val parents = impl.parents
1489
+ val parentRefinements = new mutable.LinkedHashMap [Name , Type ]
1488
1490
1489
1491
/* The type of a parent constructor. Types constructor arguments
1490
1492
* only if parent type contains uninstantiated type parameters.
@@ -1536,8 +1538,13 @@ class Namer { typer: Typer =>
1536
1538
val ptype = parentType(parent)(using completerCtx.superCallContext).dealiasKeepAnnots
1537
1539
if (cls.isRefinementClass) ptype
1538
1540
else {
1539
- val pt = checkClassType(ptype, parent.srcPos,
1540
- traitReq = parent ne parents.head, stablePrefixReq = true )
1541
+ val pt = checkClassType(
1542
+ if Feature .enabled(modularity)
1543
+ then ptype.separateRefinements(cls, parentRefinements)
1544
+ else ptype,
1545
+ parent.srcPos,
1546
+ traitReq = parent ne parents.head,
1547
+ stablePrefixReq = true )
1541
1548
if (pt.derivesFrom(cls)) {
1542
1549
val addendum = parent match {
1543
1550
case Select (qual : Super , _) if Feature .migrateTo3 =>
@@ -1564,6 +1571,21 @@ class Namer { typer: Typer =>
1564
1571
}
1565
1572
}
1566
1573
1574
+ /** Enter all parent refinements as public class members, unless a definition
1575
+ * with the same name already exists in the class.
1576
+ */
1577
+ def enterParentRefinementSyms (refinements : List [(Name , Type )]) =
1578
+ val refinedSyms = mutable.ListBuffer [Symbol ]()
1579
+ for (name, tp) <- refinements do
1580
+ if decls.lookupEntry(name) == null then
1581
+ val flags = tp match
1582
+ case tp : MethodOrPoly => Method | Synthetic | Deferred
1583
+ case _ => Synthetic | Deferred
1584
+ refinedSyms += newSymbol(cls, name, flags, tp, coord = original.rhs.span.startPos).entered
1585
+ if refinedSyms.nonEmpty then
1586
+ typr.println(i " parent refinement symbols: ${refinedSyms.toList}" )
1587
+ original.pushAttachment(ParentRefinements , refinedSyms.toList)
1588
+
1567
1589
/** If `parents` contains references to traits that have supertraits with implicit parameters
1568
1590
* add those supertraits in linearization order unless they are already covered by other
1569
1591
* parent types. For instance, in
@@ -1632,6 +1654,7 @@ class Namer { typer: Typer =>
1632
1654
cls.invalidateMemberCaches() // we might have checked for a member when parents were not known yet.
1633
1655
cls.setNoInitsFlags(parentsKind(parents), untpd.bodyKind(rest))
1634
1656
cls.setStableConstructor()
1657
+ enterParentRefinementSyms(parentRefinements.toList)
1635
1658
processExports(using localCtx)
1636
1659
defn.patchStdLibClass(cls)
1637
1660
addConstructorProxies(cls)
0 commit comments