Skip to content

Commit a01ec03

Browse files
Backport "Only cache base types when gadt state is empty" to LTS (#20869)
Backports #19562 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents ae94fb6 + 0122dc7 commit a01ec03

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,7 @@ object SymDenotations {
21792179
Stats.record("basetype cache entries")
21802180
if (!baseTp.exists) Stats.record("basetype cache NoTypes")
21812181
}
2182-
if (!tp.isProvisional && !CapturingType.isUncachable(tp))
2182+
if !(tp.isProvisional || CapturingType.isUncachable(tp) || ctx.gadt.isNarrowing) then
21832183
btrCache(tp) = baseTp
21842184
else
21852185
btrCache.remove(tp) // Remove any potential sentinel value

tests/pos/i19521.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
final abstract class PLet
3+
4+
sealed trait Expr[+P]
5+
case class ELet[+A](name: String, expr: Expr[A]) extends Expr[A | PLet]
6+
7+
def go[P](e: Expr[P]): P = e match
8+
case ELet(_, _) =>
9+
val x: Expr[P] | ELet[P] = ???
10+
val y: Expr[P] = x // conforms iff using gadt constraints
11+
// error before changes: cast from gadt reasoning was not inserted because
12+
// `Expr[P]` was erronously cached as a baseType of `Expr[P] | ELet[P]` (only true with gadt constraints)
13+
???

0 commit comments

Comments
 (0)