Skip to content

Commit d244cc9

Browse files
committed
Ignore capturing from parents when computing base type
1 parent afddb45 commit d244cc9

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import scala.util.control.NonFatal
2323
import config.Config
2424
import reporting.*
2525
import collection.mutable
26-
import cc.{CapturingType, derivedCapturingType}
26+
import cc.{CapturingType, derivedCapturingType, stripCapturing}
2727

2828
import scala.annotation.internal.sharable
2929
import scala.compiletime.uninitialized
@@ -2228,7 +2228,7 @@ object SymDenotations {
22282228
tp match {
22292229
case tp @ TypeRef(prefix, _) =>
22302230
def foldGlb(bt: Type, ps: List[Type]): Type = ps match {
2231-
case p :: ps1 => foldGlb(bt & recur(p), ps1)
2231+
case p :: ps1 => foldGlb(bt & recur(p.stripCapturing), ps1)
22322232
case _ => bt
22332233
}
22342234

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -893,20 +893,13 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
893893
canWidenAbstract && acc(true, tp)
894894

895895
def tryBaseType(cls2: Symbol) =
896-
var base = nonExprBaseType(tp1, cls2)
896+
val base = nonExprBaseType(tp1, cls2)
897897
if base.exists && (base ne tp1)
898898
&& (!caseLambda.exists
899899
|| widenAbstractOKFor(tp2)
900900
|| tp1.widen.underlyingClassRef(refinementOK = true).exists)
901901
then
902902
def checkBase =
903-
// Strip existing capturing set from base type
904-
base = base.stripCapturing
905-
// Pass capture set of tp1 to base type
906-
tp1 match
907-
case tp1 @ CapturingType(_, refs1) =>
908-
base = CapturingType(base, refs1, tp1.isBoxed)
909-
case _ =>
910903
isSubType(base, tp2, if tp1.isRef(cls2) then approx else approx.addLow)
911904
&& recordGadtUsageIf { MatchType.thatReducesUsingGadt(tp1) }
912905
if tp1.widenDealias.isInstanceOf[AndType] || base.isInstanceOf[OrType] then

0 commit comments

Comments
 (0)