File tree Expand file tree Collapse file tree 4 files changed +19
-3
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 4 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -431,7 +431,7 @@ object Phases {
431
431
final def sameParentsStartId : Int = mySameParentsStartId
432
432
// id of first phase where all symbols are guaranteed to have the same parents as in this phase
433
433
final def sameBaseTypesStartId : Int = mySameBaseTypesStartId
434
- // id of first phase where all symbols are guaranteed to have the same base tpyes as in this phase
434
+ // id of first phase where all symbols are guaranteed to have the same base types as in this phase
435
435
436
436
protected [Phases ] def init (base : ContextBase , start : Int , end : Int ): Unit = {
437
437
if (start >= FirstPhaseId )
Original file line number Diff line number Diff line change @@ -2192,7 +2192,8 @@ object SymDenotations {
2192
2192
Stats .record(" basetype cache entries" )
2193
2193
if (! baseTp.exists) Stats .record(" basetype cache NoTypes" )
2194
2194
}
2195
- if (! tp.isProvisional && ! CapturingType .isUncachable(tp))
2195
+ if ! (tp.isProvisional || CapturingType .isUncachable(tp) || ctx.gadt.isNarrowing) then
2196
+ // NOTE alternative: always try with empty gadt ctx first, can then always use cache, o.w. can try with ctx but no caching
2196
2197
btrCache(tp) = baseTp
2197
2198
else
2198
2199
btrCache.remove(tp) // Remove any potential sentinel value
Original file line number Diff line number Diff line change @@ -4075,7 +4075,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4075
4075
case CompareResult .OKwithGADTUsed
4076
4076
if pt.isValueType
4077
4077
&& ! inContext(ctx.fresh.setGadtState(GadtState (GadtConstraint .empty))) {
4078
- val res = (tree.tpe.widenExpr frozen_<:< pt)
4078
+ // tree.tpe.classSymbol.denot.asClass.invalidateBaseTypeCache() // NOTE fixes the issue
4079
+ val res = trace(i " unnecessary GADT for $tree: ${tree.tpe.widenExpr} vs $pt in ${ctx.source}" ):
4080
+ tree.tpe.widenExpr frozen_<:< pt
4079
4081
if res then
4080
4082
// we overshot; a cast is not needed, after all.
4081
4083
gadts.println(i " unnecessary GADTused for $tree: ${tree.tpe.widenExpr} vs $pt in ${ctx.source}" )
Original file line number Diff line number Diff line change
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
+ ???
You can’t perform that action at this time.
0 commit comments