Skip to content

Commit

Permalink
Widen skolem types when adding parent refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperFKorban committed Jan 31, 2025
1 parent f7e5df5 commit 8ec93ae
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
14 changes: 8 additions & 6 deletions compiler/src/dotty/tools/dotc/core/NamerOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ContextOps.enter
import TypeApplications.EtaExpansion
import collection.mutable
import config.Printers.typr
import ast.untpd

/** Operations that are shared between Namer and TreeUnpickler */
object NamerOps:
Expand Down Expand Up @@ -38,19 +39,20 @@ object NamerOps:
* unless it is null.
*/
extension (tp: Type)
def separateRefinements(cls: ClassSymbol, refinements: mutable.LinkedHashMap[Name, Type] | Null)(using Context): Type =
def separateRefinements(cls: ClassSymbol, refinements: mutable.LinkedHashMap[Name, Type] | Null, parent: untpd.Tree)(using Context): Type =
tp match
case RefinedType(tp1, rname, rinfo) =>
try tp1.separateRefinements(cls, refinements)
try tp1.separateRefinements(cls, refinements, parent)
finally
if refinements != null then
val rinfo1 = rinfo.widenSkolem
refinements(rname) = refinements.get(rname) match
case Some(tp) => tp & rinfo
case None => rinfo
case Some(tp) => tp & rinfo1
case None => rinfo1
case tp @ AnnotatedType(tp1, ann) =>
tp.derivedAnnotatedType(tp1.separateRefinements(cls, refinements), ann)
tp.derivedAnnotatedType(tp1.separateRefinements(cls, refinements, parent), ann)
case tp: RecType =>
tp.parent.substRecThis(tp, cls.thisType).separateRefinements(cls, refinements)
tp.parent.substRecThis(tp, cls.thisType).separateRefinements(cls, refinements, parent)
case tp =>
tp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ class TreeUnpickler(reader: TastyReader,
}
val parentReader = fork
val parents = readParents(withArgs = false)(using parentCtx)
val parentTypes = parents.map(_.tpe.dealiasKeepAnnots.separateRefinements(cls, null))
val parentTypes = parents.map(p => p.tpe.dealiasKeepAnnots.separateRefinements(cls, null, p))
if cls.is(JavaDefined) && parentTypes.exists(_.derivesFrom(defn.JavaAnnotationClass)) then
cls.setFlag(JavaAnnotation)
val self =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ class Namer { typer: Typer =>
else {
val pt = checkClassType(
if Feature.enabled(modularity)
then ptype.separateRefinements(cls, parentRefinements)
then ptype.separateRefinements(cls, parentRefinements, parent)
else ptype,
parent.srcPos,
traitReq = parent ne parents.head,
Expand Down
4 changes: 4 additions & 0 deletions tests/pos/i22456.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import language.experimental.modularity

class T(tracked val y: Int)
class C(tracked val x: Int) extends T(x + 1)

0 comments on commit 8ec93ae

Please sign in to comment.