Skip to content

Commit c16c7f6

Browse files
committed
Merge pull request #889 from dotty-staging/fix-#877
Fix #877
2 parents 0f04188 + 970a2bd commit c16c7f6

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

src/dotty/tools/dotc/Compiler.scala

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import Scopes._
99
import typer.{FrontEnd, Typer, Mode, ImportInfo, RefChecks}
1010
import reporting.{Reporter, ConsoleReporter}
1111
import Phases.Phase
12-
import dotty.tools.dotc.transform._
13-
import dotty.tools.dotc.transform.TreeTransforms.{TreeTransform, TreeTransformer}
14-
import dotty.tools.dotc.core.DenotTransformers.DenotTransformer
15-
import dotty.tools.dotc.core.Denotations.SingleDenotation
16-
12+
import transform._
13+
import transform.TreeTransforms.{TreeTransform, TreeTransformer}
14+
import core.DenotTransformers.DenotTransformer
15+
import core.Denotations.SingleDenotation
1716

1817
import dotty.tools.backend.jvm.{LabelDefs, GenBCode}
1918

src/dotty/tools/dotc/ast/Desugar.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ object desugar {
132132
case tparam @ TypeDef(_, ContextBounds(tbounds, cxbounds)) =>
133133
for (cxbound <- cxbounds) {
134134
val paramFlags: FlagSet = if (isPrimaryConstructor) PrivateLocalParamAccessor else Param
135-
val epname = (nme.EVIDENCE_PARAM_PREFIX.toString + epbuf.length).toTermName
135+
val epname = ctx.freshName(nme.EVIDENCE_PARAM_PREFIX).toTermName
136136
epbuf += ValDef(epname, cxbound, EmptyTree).withFlags(paramFlags | Implicit)
137137
}
138138
cpy.TypeDef(tparam)(rhs = tbounds)

src/dotty/tools/dotc/core/Contexts.scala

+10-6
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ object Contexts {
153153
protected def gadt_=(gadt: GADTMap) = _gadt = gadt
154154
def gadt: GADTMap = _gadt
155155

156+
/**The current fresh name creator */
157+
private[this] var _freshNames: FreshNameCreator = _
158+
protected def freshNames_=(freshNames: FreshNameCreator) = _freshNames = freshNames
159+
def freshNames: FreshNameCreator = _freshNames
160+
161+
def freshName(prefix: String = ""): String = freshNames.newName(prefix)
162+
def freshName(prefix: Name): String = freshName(prefix.toString)
163+
156164
/** A map in which more contextual properties can be stored */
157165
private var _moreProperties: Map[String, Any] = _
158166
protected def moreProperties_=(moreProperties: Map[String, Any]) = _moreProperties = moreProperties
@@ -423,6 +431,7 @@ object Contexts {
423431
def setDiagnostics(diagnostics: Option[StringBuilder]): this.type = { this.diagnostics = diagnostics; this }
424432
def setTypeComparerFn(tcfn: Context => TypeComparer): this.type = { this.typeComparer = tcfn(this); this }
425433
def setSearchHistory(searchHistory: SearchHistory): this.type = { this.searchHistory = searchHistory; this }
434+
def setFreshNames(freshNames: FreshNameCreator): this.type = { this.freshNames = freshNames; this }
426435
def setMoreProperties(moreProperties: Map[String, Any]): this.type = { this.moreProperties = moreProperties; this }
427436

428437
def setProperty(prop: (String, Any)): this.type = setMoreProperties(moreProperties + prop)
@@ -468,6 +477,7 @@ object Contexts {
468477
typeAssigner = TypeAssigner
469478
runInfo = new RunInfo(this)
470479
diagnostics = None
480+
freshNames = new FreshNameCreator.Default
471481
moreProperties = Map.empty
472482
typeComparer = new TypeComparer(this)
473483
searchHistory = new SearchHistory(0, Map())
@@ -498,12 +508,6 @@ object Contexts {
498508
/** The platform */
499509
val platform: Platform = new JavaPlatform
500510

501-
/** The standard fresh name creator */
502-
val freshNames = new FreshNameCreator.Default
503-
504-
def freshName(prefix: String = ""): String = freshNames.newName(prefix)
505-
def freshName(prefix: Name): String = freshName(prefix.toString)
506-
507511
/** The loader that loads the members of _root_ */
508512
def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = platform.rootLoader(root)
509513

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import parsing.Parsers.Parser
99
import config.Printers._
1010
import util.Stats._
1111
import scala.util.control.NonFatal
12+
import util.FreshNameCreator
1213

1314
class FrontEnd extends Phase {
1415

@@ -47,7 +48,8 @@ class FrontEnd extends Phase {
4748
}
4849

4950
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
50-
val unitContexts = units map (unit => ctx.fresh.setCompilationUnit(unit))
51+
val unitContexts = for (unit <- units) yield
52+
ctx.fresh.setCompilationUnit(unit).setFreshNames(new FreshNameCreator.Default)
5153
unitContexts foreach (parse(_))
5254
record("parsedTrees", ast.Trees.ntrees)
5355
unitContexts foreach (enterSyms(_))

tests/pos/i877.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class First[A]
2+
class Second[A]
3+
4+
class Foo {
5+
def foo[A: First] = {
6+
def bar[B: Second] = {
7+
val fst: First[A] = implicitly[First[A]]
8+
val snd: Second[B] = implicitly[Second[B]]
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)