Skip to content

Commit 3486eb0

Browse files
oderskyDarkDimius
authored andcommitted
Avoid creating a local dummy when retyping.
Retyping should not create new symbols and that includes local dummys.
1 parent 879a0b2 commit 3486eb0

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/dotty/tools/dotc/typer/ReTyper.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package typer
33

44
import core.Contexts._
55
import core.Types._
6-
import core.Symbols.Symbol
6+
import core.Symbols._
77
import typer.ProtoTypes._
88
import ast.{tpd, untpd}
99
import ast.Trees._
@@ -48,6 +48,8 @@ class ReTyper extends Typer {
4848
untpd.cpy.Bind(tree, tree.name, body1).withType(tree.typeOpt)
4949
}
5050

51+
override def localDummy(cls: ClassSymbol, impl: untpd.Template)(implicit ctx: Context) = impl.symbol
52+
5153
override def retrieveSym(tree: untpd.Tree)(implicit ctx: Context): Symbol = tree.symbol
5254

5355
override def localTyper(sym: Symbol) = this

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,11 +809,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
809809
val parents1 = ensureConstrCall(ensureFirstIsClass(
810810
parents mapconserve typedParent, cdef.pos.toSynthetic))
811811
val self1 = typed(self)(ctx.outer).asInstanceOf[ValDef] // outer context where class memebers are not visible
812-
val localDummy = ctx.newLocalDummy(cls, impl.pos)
813-
val body1 = typedStats(body, localDummy)(inClassContext(self1.symbol))
812+
val dummy = localDummy(cls, impl)
813+
val body1 = typedStats(body, dummy)(inClassContext(self1.symbol))
814814
checkNoDoubleDefs(cls)
815815
val impl1 = cpy.Template(impl, constr1, parents1, self1, body1)
816-
.withType(localDummy.termRef)
816+
.withType(dummy.termRef)
817817
assignType(cpy.TypeDef(cdef, mods1, name, impl1), cls)
818818

819819
// todo later: check that
@@ -825,6 +825,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
825825
// 4. Polymorphic type defs override nothing.
826826
}
827827

828+
def localDummy(cls: ClassSymbol, impl: untpd.Template)(implicit ctx: Context): Symbol =
829+
ctx.newLocalDummy(cls, impl.pos)
830+
828831
def typedImport(imp: untpd.Import, sym: Symbol)(implicit ctx: Context): Import = track("typedImport") {
829832
val expr1 = typedExpr(imp.expr, AnySelectionProto)
830833
checkStable(expr1.tpe, imp.expr.pos)

0 commit comments

Comments
 (0)