Skip to content

Commit

Permalink
Fix capture set variable installation in Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyxus committed Nov 9, 2023
1 parent dc0b43c commit c2bffc7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/cc/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
case tp: (TypeRef | AppliedType) =>
val sym = tp.typeSymbol
if sym.isClass then
sym == defn.AnyClass
sym == defn.AnyClass || !sym.isPureClass
// we assume Any is a shorthand of {cap} Any, so if Any is an upper
// bound, the type is taken to be impure.
else
Expand Down Expand Up @@ -708,4 +708,4 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
def postCheck()(using Context): Unit =
for chk <- todoAtPostCheck do chk(ctx)
todoAtPostCheck.clear()
end Setup
end Setup
5 changes: 5 additions & 0 deletions tests/pos-custom-args/captures/cc-setup-impure-classes.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import language.experimental.captureChecking

trait Resource
def id[X](x: X): x.type = x
def foo[M <: Resource](r: M^): Unit = id(r)
16 changes: 16 additions & 0 deletions tests/pos-custom-args/captures/future-traverse.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import language.experimental.captureChecking

trait Builder[-A, +C]
trait BuildFrom[-From, -A, +C] {
def newBuilder(from: From): Builder[A, C]
}

trait Future[+T] { this: Future[T]^ =>
import Future.*
def foldLeft[R](r: R): R = r
def traverse[A, B, M[X] <: IterableOnce[X]](in: M[A]^, bf: BuildFrom[M[A]^, B, M[B]^]): Unit =
foldLeft(successful(bf.newBuilder(in)))
}
object Future {
def successful[T](result: T): Future[T] = ???
}

0 comments on commit c2bffc7

Please sign in to comment.