Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widen skolem types when adding parent refinements #22476

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading