Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only cache base types when gadt state is empty #19562

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2192,7 +2192,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)
???
Loading