Skip to content

Commit a040cc6

Browse files
committed
Don't crash when calling gc() on a committed TyperState
An already-committed TyperState might be committed again when errors are flushed (cf #12827, #13150) and `commit()` calls `gc()`. This operation could crash before this commit because we attempted to instantiate type variables no longer owned by the TyperState. We fix this by clearing `ownedVars` when committing a TyperState (because after committing it no longer owns any type variable). Fixes #13407.
1 parent 427d313 commit a040cc6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class TyperState() {
162162
targetState.mergeConstraintWith(this)
163163
targetState.gc()
164164
isCommitted = true
165+
ownedVars = SimpleIdentitySet.empty
165166
}
166167

167168
/** Ensure that this constraint does not associate different TypeVars for the

tests/neg/i13407.scala

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import scala.quoted.Type
2+
3+
trait Tensor[S <: Tuple] {
4+
def sum[Axis <: Shape: Type](axis: Axis): Tensor[S] = { // error
5+
Tensor.mk
6+
}
7+
}
8+
9+
object Tensor {
10+
def mk[S <: Tuple]: Tensor[S] = new Tensor {}
11+
}
12+
13+
object Foo {
14+
val t1: Tensor[("batch", "len", "embed")] = Tensor.mk
15+
def foo(x: Any) = {
16+
17+
}
18+
foo(foo(t1.sum("len"))) // error
19+
}

0 commit comments

Comments
 (0)