Skip to content

Commit 0cd94fc

Browse files
authored
Reset comparersInUse to zero in ContextState.reset (#18915)
Fixes #18855 The code in #18855 used to crash the compiler with an out-of-bound access exception. It was because, previously, `ContextState.reset` clears the `comparers`, the cached pool of `TypeComparer`s, while keeping the variable `comparersInUse` intact. However, the `comparer` method of a context assumes `comparers` has a size greater than or equal to `comparersInUse`. So the invariant is clearly violated here and thus triggers the crash. This PR proposes a straightforward fix. Yet, the reason why only under both macros and cc this code path will be triggered remains to be investigated.
2 parents 563fab9 + 44c9674 commit 0cd94fc

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,7 @@ object Contexts {
10631063
sources.clear()
10641064
files.clear()
10651065
comparers.clear() // forces re-evaluation of top and bottom classes in TypeComparer
1066+
comparersInUse = 0
10661067

10671068
// Test that access is single threaded
10681069

tests/pos-macros/i18855/invoc.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import scala.language.experimental.captureChecking
2+
val x = run()
3+

tests/pos-macros/i18855/macro.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted.*
2+
import scala.language.experimental.captureChecking
3+
4+
def impl()(using Quotes): Expr[Unit] = '{()}
5+
inline def run(): Unit = ${impl()}
6+
7+

0 commit comments

Comments
 (0)