Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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.
  • Loading branch information
odersky committed Aug 19, 2025
commit 7db06f3f047ec34f0d29c399ed65b22dfe78cee5
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,13 @@ object TypeOps:
// Drop caps.Pure from a bound (1) at the top-level, (2) in an `&`, (3) under a type lambda.
def dropPure(tp: Type): Option[Type] = tp match
case tp @ AndType(tp1, tp2) =>
for tp1o <- dropPure(tp1); tp2o <- dropPure(tp2) yield
tp.derivedAndType(tp1o, tp2o)
dropPure(tp1) match
case Some(tp1o) =>
dropPure(tp2) match
case Some(tp2o) => Some(tp.derivedAndType(tp1o, tp2o))
case None => Some(tp1o)
case None =>
dropPure(tp2)
case tp: HKTypeLambda =>
for rt <- dropPure(tp.resType) yield
tp.derivedLambdaType(resType = rt)
Expand Down
12 changes: 12 additions & 0 deletions tests/neg/puretest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import caps.Pure
def foo[C <: Pure]() = ()
def bar[T, C <: Iterable[T] & Pure]() = ()
def baz[CC[_] <: Pure]() = ()
def bam[CC[A] <: Pure & Iterable[A]]() = ()
def test =
foo[Int]()
bar[Int, List[Int]]()
bar[Int, Iterator[Int]]() // error
baz[Seq]()
bam[Seq]()
bam[Iterator]() // error
Loading