@@ -1496,12 +1496,12 @@ class Typer extends Namer
1496
1496
cdef.withType(UnspecifiedErrorType )
1497
1497
} else {
1498
1498
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))
1500
1500
if (! ctx.isAfterTyper)
1501
1501
cls.setNoInitsFlags((NoInitsInterface /: body1) ((fs, stat) => fs & defKind(stat)))
1502
1502
1503
1503
// 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)
1505
1505
1506
1506
checkNoDoubleDefs(cls)
1507
1507
val impl1 = cpy.Template (impl)(constr1, parents1, self1, body1)
@@ -1604,15 +1604,12 @@ class Typer extends Namer
1604
1604
// Package will not exist if a duplicate type has already been entered, see
1605
1605
// `tests/neg/1708.scala`, else branch's error message should be supressed
1606
1606
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)
1614
1610
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 " )
1616
1613
}
1617
1614
1618
1615
def typedAnnotated (tree : untpd.Annotated , pt : Type )(implicit ctx : Context ): Tree = track(" typedAnnotated" ) {
@@ -1708,15 +1705,6 @@ class Typer extends Namer
1708
1705
NoSymbol
1709
1706
}
1710
1707
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
-
1720
1708
protected def localTyper (sym : Symbol ): Typer = nestedTyper.remove(sym).get
1721
1709
1722
1710
def typedUnadapted (initTree : untpd.Tree , pt : Type = WildcardType )(implicit ctx : Context ): Tree = {
@@ -1734,15 +1722,15 @@ class Typer extends Namer
1734
1722
case tree : untpd.Bind => typedBind(tree, pt)
1735
1723
case tree : untpd.ValDef =>
1736
1724
if (tree.isEmpty) tpd.EmptyValDef
1737
- else typedValDef(tree, sym)(localContext(tree, sym).setNewScope)
1725
+ else typedValDef(tree, sym)(ctx. localContext(tree, sym).setNewScope)
1738
1726
case tree : untpd.DefDef =>
1739
1727
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))
1741
1729
case tree : untpd.TypeDef =>
1742
1730
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 ))
1744
1732
else
1745
- typedTypeDef(tree, sym)(localContext(tree, sym).setNewScope)
1733
+ typedTypeDef(tree, sym)(ctx. localContext(tree, sym).setNewScope)
1746
1734
case _ => typedUnadapted(desugar(tree), pt)
1747
1735
}
1748
1736
}
@@ -1776,7 +1764,7 @@ class Typer extends Namer
1776
1764
case tree : untpd.OrTypeTree => typedOrTypeTree(tree)
1777
1765
case tree : untpd.RefinedTypeTree => typedRefinedTypeTree(tree)
1778
1766
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)
1780
1768
case tree : untpd.ByNameTypeTree => typedByNameTypeTree(tree)
1781
1769
case tree : untpd.TypeBoundsTree => typedTypeBoundsTree(tree, pt)
1782
1770
case tree : untpd.Alternative => typedAlternative(tree, pt)
0 commit comments