Skip to content

Commit

Permalink
Only cache baseTypes when gadtState is empty
Browse files Browse the repository at this point in the history
[Cherry-picked 51542ec]
  • Loading branch information
EugeneFlesselle authored and WojciechMazur committed Jun 28, 2024
1 parent 2c8480d commit 0122dc7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,7 @@ object SymDenotations {
Stats.record("basetype cache entries")
if (!baseTp.exists) Stats.record("basetype cache NoTypes")
}
if (!tp.isProvisional && !CapturingType.isUncachable(tp))
if !(tp.isProvisional || CapturingType.isUncachable(tp) || ctx.gadt.isNarrowing) then
btrCache(tp) = baseTp
else
btrCache.remove(tp) // Remove any potential sentinel value
Expand Down
13 changes: 13 additions & 0 deletions tests/pos/i19521.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

final abstract class PLet

sealed trait Expr[+P]
case class ELet[+A](name: String, expr: Expr[A]) extends Expr[A | PLet]

def go[P](e: Expr[P]): P = e match
case ELet(_, _) =>
val x: Expr[P] | ELet[P] = ???
val y: Expr[P] = x // conforms iff using gadt constraints
// error before changes: cast from gadt reasoning was not inserted because
// `Expr[P]` was erronously cached as a baseType of `Expr[P] | ELet[P]` (only true with gadt constraints)
???

0 comments on commit 0122dc7

Please sign in to comment.