Skip to content

Commit 0a759cc

Browse files
Only cache baseTypes when gadtState is empty
1 parent 1716bcd commit 0a759cc

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
@@ -2192,7 +2192,7 @@ object SymDenotations {
21922192
Stats.record("basetype cache entries")
21932193
if (!baseTp.exists) Stats.record("basetype cache NoTypes")
21942194
}
2195-
if (!tp.isProvisional && !CapturingType.isUncachable(tp))
2195+
if !(tp.isProvisional || CapturingType.isUncachable(tp) || ctx.gadt.isNarrowing) then
21962196
btrCache(tp) = baseTp
21972197
else
21982198
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)