Skip to content

Commit 3a252a7

Browse files
committed
Fix new problem uncovered by AndType fix
Fixes a new problem exhibited in the ZIO 1 code base that got uncovered by the previous fix to AndTypes.
1 parent 71dd329 commit 3a252a7

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,10 +926,13 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
926926
then
927927
isSubType(base, tp2, if (tp1.isRef(cls2)) approx else approx.addLow)
928928
&& recordGadtUsageIf { MatchType.thatReducesUsingGadt(tp1) }
929-
|| base.isInstanceOf[OrType] && fourthTry
930-
// if base is a disjunction, this might have come from a tp1 type that
929+
|| base.isInstanceOf[AndOrType] && fourthTry
930+
// If base is a disjunction, this might have come from a tp1 type that
931931
// expands to a match type. In this case, we should try to reduce the type
932932
// and compare the redux. This is done in fourthTry
933+
// If base is a conjunction, it could be that one of the original
934+
// branches of the AndType tp1 conforms to tp2, but its base type does
935+
// not. So we need to also fall back to fourthTry. Test case is i18226a.scala.
933936
else fourthTry
934937
end tryBaseType
935938

tests/neg-custom-args/allow-deep-subtypes/i5877.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ object Main {
2020

2121
def testHasThisType(): Unit = {
2222
def testSelf[PThis <: HasThisType[_ <: PThis]](that: HasThisType[PThis]): Unit = {
23-
val thatSelf = that.self() // error: recursion limit exceeded
23+
val thatSelf = that.self()
2424
// that.self().type <: that.This
2525
assert(implicitly[thatSelf.type <:< that.This] != null)
2626
}

tests/pos/i18226a.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Has[A]
2+
trait Foo
3+
4+
class TestAspect[+LowerR, -UpperR]
5+
6+
class Spec[-R] {
7+
def foo[R1 <: R](aspect: TestAspect[R1, R1]): Unit = {}
8+
}
9+
10+
class SuiteBuilder[R <: Has[_]] {
11+
def toSpec(
12+
spec: Spec[R & Has[Foo]],
13+
aspect: TestAspect[
14+
R & Has[Foo],
15+
R & Has[Foo]
16+
]
17+
) =
18+
spec.foo(aspect)
19+
}

0 commit comments

Comments
 (0)