@@ -1496,12 +1496,12 @@ class Typer extends Namer
14961496 cdef.withType(UnspecifiedErrorType )
14971497 } else {
14981498 val dummy = localDummy(cls, impl)
1499- val body1 = typedStats(impl.body, dummy)(inClassContext(self1.symbol))
1499+ val body1 = typedStats(impl.body, dummy)(ctx. inClassContext(self1.symbol))
15001500 if (! ctx.isAfterTyper)
15011501 cls.setNoInitsFlags((NoInitsInterface /: body1) ((fs, stat) => fs & defKind(stat)))
15021502
15031503 // Expand comments and type usecases
1504- cookComments(body1.map(_.symbol), self1.symbol)(localContext(cdef, cls).setNewScope)
1504+ cookComments(body1.map(_.symbol), self1.symbol)(ctx. localContext(cdef, cls).setNewScope)
15051505
15061506 checkNoDoubleDefs(cls)
15071507 val impl1 = cpy.Template (impl)(constr1, parents1, self1, body1)
@@ -1604,15 +1604,12 @@ class Typer extends Namer
16041604 // Package will not exist if a duplicate type has already been entered, see
16051605 // `tests/neg/1708.scala`, else branch's error message should be supressed
16061606 if (pkg.exists) {
1607- val packageContext =
1608- if (pkg is Package ) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree)
1609- else {
1610- ctx.error(PackageNameAlreadyDefined (pkg), tree.pos)
1611- ctx
1612- }
1613- val stats1 = typedStats(tree.stats, pkg.moduleClass)(packageContext)
1607+ if (! pkg.is(Package )) ctx.error(PackageNameAlreadyDefined (pkg), tree.pos)
1608+ val packageCtx = ctx.packageContext(tree, pkg)
1609+ val stats1 = typedStats(tree.stats, pkg.moduleClass)(packageCtx)
16141610 cpy.PackageDef (tree)(pid1.asInstanceOf [RefTree ], stats1) withType pkg.termRef
1615- } else errorTree(tree, i " package ${tree.pid.name} does not exist " )
1611+ }
1612+ else errorTree(tree, i " package ${tree.pid.name} does not exist " )
16161613 }
16171614
16181615 def typedAnnotated (tree : untpd.Annotated , pt : Type )(implicit ctx : Context ): Tree = track(" typedAnnotated" ) {
@@ -1708,15 +1705,6 @@ class Typer extends Namer
17081705 NoSymbol
17091706 }
17101707
1711- /** A fresh local context with given tree and owner.
1712- * Owner might not exist (can happen for self valdefs), in which case
1713- * no owner is set in result context
1714- */
1715- protected def localContext (tree : untpd.Tree , owner : Symbol )(implicit ctx : Context ): FreshContext = {
1716- val freshCtx = ctx.fresh.setTree(tree)
1717- if (owner.exists) freshCtx.setOwner(owner) else freshCtx
1718- }
1719-
17201708 protected def localTyper (sym : Symbol ): Typer = nestedTyper.remove(sym).get
17211709
17221710 def typedUnadapted (initTree : untpd.Tree , pt : Type = WildcardType )(implicit ctx : Context ): Tree = {
@@ -1734,15 +1722,15 @@ class Typer extends Namer
17341722 case tree : untpd.Bind => typedBind(tree, pt)
17351723 case tree : untpd.ValDef =>
17361724 if (tree.isEmpty) tpd.EmptyValDef
1737- else typedValDef(tree, sym)(localContext(tree, sym).setNewScope)
1725+ else typedValDef(tree, sym)(ctx. localContext(tree, sym).setNewScope)
17381726 case tree : untpd.DefDef =>
17391727 val typer1 = localTyper(sym)
1740- typer1.typedDefDef(tree, sym)(localContext(tree, sym).setTyper(typer1))
1728+ typer1.typedDefDef(tree, sym)(ctx. localContext(tree, sym).setTyper(typer1))
17411729 case tree : untpd.TypeDef =>
17421730 if (tree.isClassDef)
1743- typedClassDef(tree, sym.asClass)(localContext(tree, sym).setMode(ctx.mode &~ Mode .InSuperCall ))
1731+ typedClassDef(tree, sym.asClass)(ctx. localContext(tree, sym).setMode(ctx.mode &~ Mode .InSuperCall ))
17441732 else
1745- typedTypeDef(tree, sym)(localContext(tree, sym).setNewScope)
1733+ typedTypeDef(tree, sym)(ctx. localContext(tree, sym).setNewScope)
17461734 case _ => typedUnadapted(desugar(tree), pt)
17471735 }
17481736 }
@@ -1776,7 +1764,7 @@ class Typer extends Namer
17761764 case tree : untpd.OrTypeTree => typedOrTypeTree(tree)
17771765 case tree : untpd.RefinedTypeTree => typedRefinedTypeTree(tree)
17781766 case tree : untpd.AppliedTypeTree => typedAppliedTypeTree(tree)
1779- case tree : untpd.LambdaTypeTree => typedLambdaTypeTree(tree)(localContext(tree, NoSymbol ).setNewScope)
1767+ case tree : untpd.LambdaTypeTree => typedLambdaTypeTree(tree)(ctx. localContext(tree, NoSymbol ).setNewScope)
17801768 case tree : untpd.ByNameTypeTree => typedByNameTypeTree(tree)
17811769 case tree : untpd.TypeBoundsTree => typedTypeBoundsTree(tree, pt)
17821770 case tree : untpd.Alternative => typedAlternative(tree, pt)
0 commit comments