@@ -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,7 +1538,8 @@ 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,
1541
+ val pt = checkClassType(
1542
+ ptype.separateRefinements(cls, parentRefinements), parent.srcPos,
1540
1543
traitReq = parent ne parents.head, stablePrefixReq = true )
1541
1544
if (pt.derivesFrom(cls)) {
1542
1545
val addendum = parent match {
@@ -1564,6 +1567,21 @@ class Namer { typer: Typer =>
1564
1567
}
1565
1568
}
1566
1569
1570
+ /** Enter all parent refinements as public class members, unless a definition
1571
+ * with the same name already exists in the class.
1572
+ */
1573
+ def enterParentRefinementSyms (refinements : List [(Name , Type )]) =
1574
+ val refinedSyms = mutable.ListBuffer [Symbol ]()
1575
+ for (name, tp) <- refinements do
1576
+ if decls.lookupEntry(name) == null then
1577
+ val flags = tp match
1578
+ case tp : MethodOrPoly => Method | Synthetic | Deferred
1579
+ case _ => Synthetic | Deferred
1580
+ refinedSyms += newSymbol(cls, name, flags, tp, coord = original.rhs.span.startPos).entered
1581
+ if refinedSyms.nonEmpty then
1582
+ typr.println(i " parent refinement symbols: ${refinedSyms.toList}" )
1583
+ original.pushAttachment(ParentRefinements , refinedSyms.toList)
1584
+
1567
1585
/** If `parents` contains references to traits that have supertraits with implicit parameters
1568
1586
* add those supertraits in linearization order unless they are already covered by other
1569
1587
* parent types. For instance, in
@@ -1632,6 +1650,7 @@ class Namer { typer: Typer =>
1632
1650
cls.invalidateMemberCaches() // we might have checked for a member when parents were not known yet.
1633
1651
cls.setNoInitsFlags(parentsKind(parents), untpd.bodyKind(rest))
1634
1652
cls.setStableConstructor()
1653
+ enterParentRefinementSyms(parentRefinements.toList)
1635
1654
processExports(using localCtx)
1636
1655
defn.patchStdLibClass(cls)
1637
1656
addConstructorProxies(cls)
0 commit comments