Skip to content

Commit

Permalink
Move setAbstractTrackedInfo to Namer.Completer
Browse files Browse the repository at this point in the history
  • Loading branch information
mbovel committed Nov 1, 2024
1 parent 567b2c1 commit 28b5725
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
11 changes: 11 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,16 @@ class Namer { typer: Typer =>
case _ =>
}

private def setAbstractTrackedInfo(sym: Symbol)(using Context): Unit =
if !sym.flags.is(ParamAccessor) && !sym.flags.is(Param) then
if sym.allOverriddenSymbols.exists(_.flags.is(Tracked)) then
sym.setFlag(Tracked)
if sym.flags.is(Tracked) then
original match
case tree: untpd.ValDef if tree.tpt.isEmpty =>
sym.info = typedAheadExpr(tree.rhs).tpe
case _ => ()

/** Invalidate `denot` by overwriting its info with `NoType` if
* `denot` is a compiler generated case class method that clashes
* with a user-defined method in the same scope with a matching type.
Expand Down Expand Up @@ -989,6 +999,7 @@ class Namer { typer: Typer =>
addInlineInfo(sym)
denot.info = typeSig(sym)
invalidateIfClashingSynthetic(denot)
setAbstractTrackedInfo(sym)
Checking.checkWellFormed(sym)
denot.info = avoidPrivateLeaks(sym)
}
Expand Down
16 changes: 3 additions & 13 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2834,20 +2834,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
case rhs =>
excludeDeferredGiven(rhs, sym):
typedExpr(_, tpt1.tpe.widenExpr)
setAbstractTrackedInfo(sym, rhs1, tpt)
val tpt2 = if sym.flags.is(Tracked) && tpt.isEmpty && !sym.flags.is(ParamAccessor) && !sym.flags.is(Param) then TypeTree(rhs1.tpe) else tpt1
val vdef2 = assignType(cpy.ValDef(vdef)(name, tpt2, rhs1), sym)
postProcessInfo(vdef2, sym)
vdef2.setDefTree
val vdef1 = assignType(cpy.ValDef(vdef)(name, tpt1, rhs1), sym)
postProcessInfo(vdef1, sym)
vdef1.setDefTree
}

private def setAbstractTrackedInfo(sym: Symbol, rhs: Tree, tpt: untpd.Tree)(using Context): Unit =
if !sym.flags.is(ParamAccessor) && !sym.flags.is(Param) then
if sym.allOverriddenSymbols.exists(_.flags.is(Tracked)) then
sym.setFlag(Tracked)
if sym.flags.is(Tracked) && tpt.isEmpty then
sym.info = rhs.tpe

private def retractDefDef(sym: Symbol)(using Context): Tree =
// it's a discarded method (synthetic case class method or synthetic java record constructor or overridden member), drop it
val canBeInvalidated: Boolean =
Expand Down
11 changes: 11 additions & 0 deletions tests/pos/abstract-tracked-2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import scala.language.experimental.modularity
import scala.language.future

abstract class Vec:
tracked val size: Int

@main def main =
val v = new Vec:
val size0: size.type = 10
val size = 10
val size1: size.type = 10

0 comments on commit 28b5725

Please sign in to comment.