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 600859a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 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
9 changes: 0 additions & 9 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2834,20 +2834,11 @@ 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
}

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
8 changes: 8 additions & 0 deletions tests/pos/abstract-tracked-2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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 600859a

Please sign in to comment.