Skip to content

Commit 3ce904f

Browse files
committed
Merge pull request #352 from olhotak/fix-cacheiscope
Fix #347 implicitScope for the case when implicit scopes cannot be cached
2 parents 1ab02ce + 5409448 commit 3ce904f

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -337,25 +337,29 @@ trait ImplicitRunInfo { self: RunInfo =>
337337
/** The implicit scope of type `tp`
338338
* @param isLifted Type `tp` is the result of a `liftToClasses` application
339339
*/
340-
def iscope(tp: Type, isLifted: Boolean = false): OfTypeImplicits =
340+
def iscope(tp: Type, isLifted: Boolean = false): OfTypeImplicits = {
341+
def computeIScope(cacheResult: Boolean) = {
342+
val savedEphemeral = ctx.typerState.ephemeral
343+
ctx.typerState.ephemeral = false
344+
try {
345+
val liftedTp = if (isLifted) tp else liftToClasses(tp)
346+
val result =
347+
if (liftedTp ne tp) iscope(liftedTp, isLifted = true)
348+
else ofTypeImplicits(collectCompanions(tp))
349+
if (ctx.typerState.ephemeral) record("ephemeral cache miss: implicitScope")
350+
else if(cacheResult) implicitScopeCache(tp) = result
351+
result
352+
}
353+
finally ctx.typerState.ephemeral |= savedEphemeral
354+
}
355+
341356
if (tp.hash == NotCached || !Config.cacheImplicitScopes)
342-
ofTypeImplicits(collectCompanions(tp))
357+
computeIScope(cacheResult = false)
343358
else implicitScopeCache get tp match {
344359
case Some(is) => is
345-
case None =>
346-
val savedEphemeral = ctx.typerState.ephemeral
347-
ctx.typerState.ephemeral = false
348-
try {
349-
val liftedTp = if (isLifted) tp else liftToClasses(tp)
350-
val result =
351-
if (liftedTp ne tp) iscope(liftedTp, isLifted = true)
352-
else ofTypeImplicits(collectCompanions(tp))
353-
if (ctx.typerState.ephemeral) record("ephemeral cache miss: implicitScope")
354-
else implicitScopeCache(tp) = result
355-
result
356-
}
357-
finally ctx.typerState.ephemeral |= savedEphemeral
358-
}
360+
case None => computeIScope(cacheResult = true)
361+
}
362+
}
359363

360364
iscope(tp)
361365
}

0 commit comments

Comments
 (0)