Skip to content

Commit 6c0b801

Browse files
committed
Fix #7965: Deal with AndTypes in joins
Allow that the base type of a join may be a conjunction.
1 parent 193f7de commit 6c0b801

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
212212
tp1.derivedAppliedType(
213213
mergeRefinedOrApplied(tycon1, tycon2),
214214
ctx.typeComparer.lubArgs(args1, args2, tycon1.typeParams))
215+
case AndType(tp21, tp22) =>
216+
mergeRefinedOrApplied(tp1, tp21) & mergeRefinedOrApplied(tp1, tp22)
215217
case _ => fail
216218
}
217219
case tp1 @ TypeRef(pre1, _) =>
@@ -220,6 +222,8 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
220222
tp1.derivedSelect(pre1 | pre2)
221223
case _ => fail
222224
}
225+
case AndType(tp11, tp12) =>
226+
mergeRefinedOrApplied(tp11, tp2) & mergeRefinedOrApplied(tp12, tp2)
223227
case _ => fail
224228
}
225229
}

tests/pos/i7965.scala

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
class Has[A]
2+
trait X
3+
trait Y
4+
trait Z
5+
6+
abstract class Test {
7+
val x: Has[X] | (Has[Y] & Has[Z])
8+
def foo[T <: Has[_]](has: T): T = has
9+
foo(x)
10+
}
11+
12+
trait ZLayer[-RIn, +E, +ROut <: Has[_]] {
13+
def >>>[E1 >: E, ROut2 <: Has[_]](that: ZLayer[ROut, E1, ROut2]): ZLayer[RIn, E1, ROut2]
14+
def ++[E1 >: E, RIn2, ROut1 >: ROut <: Has[_], ROut2 <: Has[_]](that: ZLayer[RIn2, E1, ROut2]): ZLayer[RIn with RIn2, E1, ROut1 with ROut2]
15+
}
16+
object ZLayer {
17+
type NoDeps[+E, +B <: Has[_]] = ZLayer[Any, E, B]
18+
}
19+
20+
type ServiceA = Has[ServiceA.Service]
21+
object ServiceA {
22+
trait Service
23+
val live: ZLayer.NoDeps[Nothing, ServiceA] = ???
24+
}
25+
26+
type ServiceB = Has[ServiceB.Service]
27+
object ServiceB {
28+
trait Service
29+
val live: ZLayer.NoDeps[Nothing, ServiceB] = ???
30+
}
31+
32+
type ServiceC = Has[ServiceC.Service]
33+
object ServiceC {
34+
trait Service
35+
val live: ZLayer.NoDeps[Nothing, ServiceC] = ???
36+
}
37+
38+
type ServiceD = Has[ServiceD.Service]
39+
object ServiceD {
40+
trait Service
41+
val live: ZLayer.NoDeps[ServiceC, ServiceD with ServiceC] = ???
42+
}
43+
44+
val combined =
45+
ServiceA.live >>>
46+
(ServiceB.live ++ (ServiceC.live >>> ServiceD.live))

0 commit comments

Comments
 (0)