Skip to content

Commit 4e349cc

Browse files
committed
Fix joins and join approximations of capturing types
1 parent e15bfc4 commit 4e349cc

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,8 +2090,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
20902090
if (tp1 eq tp2) tp1
20912091
else if (!tp1.exists) tp1
20922092
else if (!tp2.exists) tp2
2093-
else if tp1.isAny && !tp2.isLambdaSub || tp1.isAnyKind || isBottom(tp2) then tp1
2094-
else if tp2.isAny && !tp1.isLambdaSub || tp2.isAnyKind || isBottom(tp1) then tp2
2093+
else if tp1.isAny && !tp2.isLambdaSub && tp2.noCaptures || tp1.isAnyKind || isBottom(tp2) then tp1
2094+
else if tp2.isAny && !tp1.isLambdaSub && tp1.noCaptures || tp2.isAnyKind || isBottom(tp1) then tp2
20952095
else
20962096
def mergedLub(tp1: Type, tp2: Type): Type = {
20972097
tp1.atoms match

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,23 @@ object TypeOps:
266266
case _ => false
267267
}
268268

269-
// Step 1: Get RecTypes and ErrorTypes out of the way,
269+
// Step 1: Get RecTypes and ErrorTypes and CapturingTypes out of the way,
270270
tp1 match {
271-
case tp1: RecType => return tp1.rebind(approximateOr(tp1.parent, tp2))
272-
case err: ErrorType => return err
271+
case tp1: RecType =>
272+
return tp1.rebind(approximateOr(tp1.parent, tp2))
273+
case tp1: CapturingType =>
274+
return tp1.derivedCapturingType(approximateOr(tp1.parent, tp2), tp1.ref)
275+
case err: ErrorType =>
276+
return err
273277
case _ =>
274278
}
275279
tp2 match {
276-
case tp2: RecType => return tp2.rebind(approximateOr(tp1, tp2.parent))
277-
case err: ErrorType => return err
280+
case tp2: RecType =>
281+
return tp2.rebind(approximateOr(tp1, tp2.parent))
282+
case tp2: CapturingType =>
283+
return tp2.derivedCapturingType(approximateOr(tp1, tp2.parent), tp2.ref)
284+
case err: ErrorType =>
285+
return err
278286
case _ =>
279287
}
280288

0 commit comments

Comments
 (0)