@@ -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.
@@ -1499,6 +1500,7 @@ class Namer { typer: Typer =>
1499
1500
/** The type signature of a ClassDef with given symbol */
1500
1501
override def completeInCreationContext (denot : SymDenotation ): Unit = {
1501
1502
val parents = impl.parents
1503
+ val parentRefinements = new mutable.LinkedHashMap [Name , Type ]
1502
1504
1503
1505
/* The type of a parent constructor. Types constructor arguments
1504
1506
* only if parent type contains uninstantiated type parameters.
@@ -1550,8 +1552,13 @@ class Namer { typer: Typer =>
1550
1552
val ptype = parentType(parent)(using completerCtx.superCallContext).dealiasKeepAnnots
1551
1553
if (cls.isRefinementClass) ptype
1552
1554
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 )
1555
1562
if (pt.derivesFrom(cls)) {
1556
1563
val addendum = parent match {
1557
1564
case Select (qual : Super , _) if Feature .migrateTo3 =>
@@ -1578,6 +1585,21 @@ class Namer { typer: Typer =>
1578
1585
}
1579
1586
}
1580
1587
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
+
1581
1603
/** If `parents` contains references to traits that have supertraits with implicit parameters
1582
1604
* add those supertraits in linearization order unless they are already covered by other
1583
1605
* parent types. For instance, in
@@ -1646,6 +1668,7 @@ class Namer { typer: Typer =>
1646
1668
cls.invalidateMemberCaches() // we might have checked for a member when parents were not known yet.
1647
1669
cls.setNoInitsFlags(parentsKind(parents), untpd.bodyKind(rest))
1648
1670
cls.setStableConstructor()
1671
+ enterParentRefinementSyms(parentRefinements.toList)
1649
1672
processExports(using localCtx)
1650
1673
defn.patchStdLibClass(cls)
1651
1674
addConstructorProxies(cls)
0 commit comments