Skip to content

Commit 4b97e1d

Browse files
committed
Enhancement: Add missing case for comparison of capturing types.
Add a case for cases like x.type <:< {r} (A | x.type) where `x` captures `r`. # Conflicts: # tests/pos-with-compiler-cc/dotc/core/Types.scala
1 parent b21867f commit 4b97e1d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,11 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
826826
if refs1.isAlwaysEmpty then recur(tp1, parent2)
827827
else subCaptures(refs1, refs2, frozenConstraint).isOK
828828
&& sameBoxed(tp1, tp2, refs1)
829-
&& recur(tp1.widen.stripCapturing, parent2)
829+
&& (recur(tp1.widen.stripCapturing, parent2)
830+
|| tp1.isInstanceOf[SingletonType] && recur(tp1, parent2)
831+
// this alternative is needed in case the right hand side is a
832+
// capturing type that contains the lhs as an |-alternative.
833+
)
830834
catch case ex: AssertionError =>
831835
println(i"assertion failed while compare captured $tp1 <:< $tp2")
832836
throw ex
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Denotation
2+
abstract class SingleDenotation extends Denotation
3+
def goRefined: Denotation =
4+
val foo: Denotation = ???
5+
val joint = foo
6+
joint match
7+
case joint: SingleDenotation =>
8+
joint
9+
case _ =>
10+
joint

0 commit comments

Comments
 (0)