From 600859a79ae28e94f43e687429f559220260bf31 Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Fri, 1 Nov 2024 14:49:31 +0100 Subject: [PATCH] Move setAbstractTrackedInfo to Namer.Completer --- compiler/src/dotty/tools/dotc/typer/Namer.scala | 11 +++++++++++ compiler/src/dotty/tools/dotc/typer/Typer.scala | 9 --------- tests/pos/abstract-tracked-2.scala | 8 ++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 tests/pos/abstract-tracked-2.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 0849e57b8c7d..680af14ba9b3 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -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. @@ -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) } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index ca1a2a98c55d..26d54ea91b30 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -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 = diff --git a/tests/pos/abstract-tracked-2.scala b/tests/pos/abstract-tracked-2.scala new file mode 100644 index 000000000000..2709a37d1d34 --- /dev/null +++ b/tests/pos/abstract-tracked-2.scala @@ -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