From 0a759cc40699d5191c9f7d334e21ec7887cbdb17 Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Mon, 29 Jan 2024 11:07:10 +0100 Subject: [PATCH] Only cache baseTypes when gadtState is empty --- .../src/dotty/tools/dotc/core/SymDenotations.scala | 2 +- tests/pos/i19521.scala | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i19521.scala diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 74eb99c1efd9..13eb5ce8b5ba 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -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 diff --git a/tests/pos/i19521.scala b/tests/pos/i19521.scala new file mode 100644 index 000000000000..19230fa4ed69 --- /dev/null +++ b/tests/pos/i19521.scala @@ -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) + ???