Skip to content

Commit 7db06f3

Browse files
committed
Fix logic for &-types with Pure
The previous logic would completely drop an &-type containing a Pure. But we should instead keep the other parts.
1 parent 60aa9a9 commit 7db06f3

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,13 @@ object TypeOps:
710710
// Drop caps.Pure from a bound (1) at the top-level, (2) in an `&`, (3) under a type lambda.
711711
def dropPure(tp: Type): Option[Type] = tp match
712712
case tp @ AndType(tp1, tp2) =>
713-
for tp1o <- dropPure(tp1); tp2o <- dropPure(tp2) yield
714-
tp.derivedAndType(tp1o, tp2o)
713+
dropPure(tp1) match
714+
case Some(tp1o) =>
715+
dropPure(tp2) match
716+
case Some(tp2o) => Some(tp.derivedAndType(tp1o, tp2o))
717+
case None => Some(tp1o)
718+
case None =>
719+
dropPure(tp2)
715720
case tp: HKTypeLambda =>
716721
for rt <- dropPure(tp.resType) yield
717722
tp.derivedLambdaType(resType = rt)

tests/neg/puretest.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import caps.Pure
2+
def foo[C <: Pure]() = ()
3+
def bar[T, C <: Iterable[T] & Pure]() = ()
4+
def baz[CC[_] <: Pure]() = ()
5+
def bam[CC[A] <: Pure & Iterable[A]]() = ()
6+
def test =
7+
foo[Int]()
8+
bar[Int, List[Int]]()
9+
bar[Int, Iterator[Int]]() // error
10+
baz[Seq]()
11+
bam[Seq]()
12+
bam[Iterator]() // error

0 commit comments

Comments
 (0)