Skip to content

Commit a43d39a

Browse files
committed
Workaround scala#742 and add a test for it.
Making a correct fix could take some time, and I want to find other issues before I start working on this one.
1 parent 1512957 commit a43d39a

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,25 +177,26 @@ object Contexts {
177177
/** The new implicit references that are introduced by this scope */
178178
private var implicitsCache: ContextualImplicits = null
179179
def implicits: ContextualImplicits = {
180-
if (implicitsCache == null )
181-
implicitsCache = {
182-
val implicitRefs: List[TermRef] =
183-
if (isClassDefContext)
184-
try owner.thisType.implicitMembers
185-
catch {
186-
case ex: CyclicReference => Nil
187-
}
188-
else if (isImportContext) importInfo.importedImplicits
189-
else if (isNonEmptyScopeContext) scope.implicitDecls
190-
else Nil
191-
val outerImplicits =
192-
if (isImportContext && importInfo.hiddenRoot.exists)
193-
outer.implicits exclude importInfo.hiddenRoot
194-
else
195-
outer.implicits
196-
if (implicitRefs.isEmpty) outerImplicits
197-
else new ContextualImplicits(implicitRefs, outerImplicits)(this)
180+
if (implicitsCache == null ) {
181+
val outerImplicits =
182+
if (isImportContext && importInfo.hiddenRoot.exists)
183+
outer.implicits exclude importInfo.hiddenRoot
184+
else
185+
outer.implicits
186+
try
187+
implicitsCache = {
188+
val implicitRefs: List[TermRef] =
189+
if (isClassDefContext) owner.thisType.implicitMembers
190+
else if (isImportContext) importInfo.importedImplicits
191+
else if (isNonEmptyScopeContext) scope.implicitDecls
192+
else Nil
193+
if (implicitRefs.isEmpty) outerImplicits
194+
else new ContextualImplicits(implicitRefs, outerImplicits)(this)
195+
}
196+
catch {
197+
case ex: CyclicReference => implicitsCache = outerImplicits
198198
}
199+
}
199200
implicitsCache
200201
}
201202

tests/pending/run/StackMap.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
var implicitsCache = null
3+
4+
def main(args: Array[String]): Unit = {
5+
implicitsCache = try{null} catch { case ex: Exception => null }
6+
}
7+
}

0 commit comments

Comments
 (0)