diff --git a/compiler/src/dotty/tools/dotc/cc/Setup.scala b/compiler/src/dotty/tools/dotc/cc/Setup.scala index 270fd9322a88..85942950f317 100644 --- a/compiler/src/dotty/tools/dotc/cc/Setup.scala +++ b/compiler/src/dotty/tools/dotc/cc/Setup.scala @@ -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 @@ -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 \ No newline at end of file +end Setup diff --git a/tests/pos-custom-args/captures/cc-setup-impure-classes.scala b/tests/pos-custom-args/captures/cc-setup-impure-classes.scala new file mode 100644 index 000000000000..db88851b6a52 --- /dev/null +++ b/tests/pos-custom-args/captures/cc-setup-impure-classes.scala @@ -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) diff --git a/tests/pos-custom-args/captures/future-traverse.scala b/tests/pos-custom-args/captures/future-traverse.scala new file mode 100644 index 000000000000..5aedc5d29852 --- /dev/null +++ b/tests/pos-custom-args/captures/future-traverse.scala @@ -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] = ??? +}