diff --git a/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala b/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala index 40fc6eb8f1de..faae83fd3456 100644 --- a/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala +++ b/compiler/src/dotty/tools/dotc/cc/CaptureOps.scala @@ -280,9 +280,9 @@ extension (tp: Type) case tp: (TypeRef | AppliedType) => val sym = tp.typeSymbol if sym.isClass then sym.isPureClass - else tp.superType.isAlwaysPure + else !tp.superType.isAny && tp.superType.isAlwaysPure case tp: TypeProxy => - tp.superType.isAlwaysPure + !tp.superType.isAny && tp.superType.isAlwaysPure case tp: AndType => tp.tp1.isAlwaysPure || tp.tp2.isAlwaysPure case tp: OrType => diff --git a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala index c79830115212..fb0a5b8b59b2 100644 --- a/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala +++ b/compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala @@ -1059,14 +1059,24 @@ class CheckCaptures extends Recheck, SymTransformer: def canUseInferred = // If canUseInferred is false, all capturing types in the type of `sym` need to be given explicitly sym.isLocalToCompilationUnit // Symbols that can't be seen outside the compilation unit can always have inferred types - || sym.privateWithin == defn.EmptyPackageClass - // We make an exception for private symbols in a toplevel file in the empty package + || ctx.owner.enclosingPackageClass.isEmptyPackage + // We make an exception for symbols in the empty package. // these could theoretically be accessed from other files in the empty package, but - // it would be too annoying to require explicit types. + // usually it would be too annoying to require explicit types. || sym.name.is(DefaultGetterName) // Default getters are exempted since otherwise it would be // too annoying. This is a hole since a defualt getter's result type // might leak into a type variable. + def fail(tree: Tree, expected: Type, addenda: Addenda): Unit = + def maybeResult = if sym.is(Method) then " result" else "" + report.error( + em"""$sym needs an explicit$maybeResult type because the inferred type does not conform to + |the type that is externally visible in other compilation units. + | + | Inferred type : ${tree.tpe} + | Externally visible type: $expected""", + tree.srcPos) + def addenda(expected: Type) = new Addenda: override def toAdd(using Context) = def result = if tree.isInstanceOf[ValDef] then"" else " result" @@ -1083,7 +1093,7 @@ class CheckCaptures extends Recheck, SymTransformer: val expected = tpt.tpe.dropAllRetains todoAtPostCheck += { () => withCapAsRoot: - checkConformsExpr(tp, expected, tree.rhs, addenda(expected)) + testAdapted(tp, expected, tree.rhs, addenda(expected))(fail) // The check that inferred <: expected is done after recheck so that it // does not interfere with normal rechecking by constraining capture set variables. } @@ -1322,7 +1332,12 @@ class CheckCaptures extends Recheck, SymTransformer: * where local capture roots are instantiated to root variables. */ override def checkConformsExpr(actual: Type, expected: Type, tree: Tree, addenda: Addenda)(using Context): Type = + testAdapted(actual, expected, tree, addenda)(err.typeMismatch) + + inline def testAdapted(actual: Type, expected: Type, tree: Tree, addenda: Addenda) + (fail: (Tree, Type, Addenda) => Unit)(using Context): Type = var expected1 = alignDependentFunction(expected, actual.stripCapturing) + val falseDeps = expected1 ne expected val actualBoxed = adapt(actual, expected1, tree) //println(i"check conforms $actualBoxed <<< $expected1") @@ -1332,26 +1347,23 @@ class CheckCaptures extends Recheck, SymTransformer: TypeComparer.compareResult(isCompatible(actualBoxed, expected1)) match case TypeComparer.CompareResult.Fail(notes) => capt.println(i"conforms failed for ${tree}: $actual vs $expected") - err.typeMismatch(tree.withType(actualBoxed), expected1, - addApproxAddenda( - addenda ++ errorNotes(notes), - expected1)) + if falseDeps then expected1 = unalignFunction(expected1) + fail(tree.withType(actualBoxed), expected1, + addApproxAddenda(addenda ++ errorNotes(notes), expected1)) actual case /*OK*/ _ => if debugSuccesses then tree match - case Ident(_) => - println(i"SUCCESS $tree for $actual <:< $expected:\n${TypeComparer.explained(_.isSubType(actualBoxed, expected1))}") - case _ => + case Ident(_) => + println(i"SUCCESS $tree for $actual <:< $expected:\n${TypeComparer.explained(_.isSubType(actualBoxed, expected1))}") + case _ => actualBoxed - end checkConformsExpr + end testAdapted /** Turn `expected` into a dependent function when `actual` is dependent. */ private def alignDependentFunction(expected: Type, actual: Type)(using Context): Type = def recur(expected: Type): Type = expected.dealias match - case expected0 @ CapturingType(eparent, refs) => - val eparent1 = recur(eparent) - if eparent1 eq eparent then expected - else CapturingType(eparent1, refs, boxed = expected0.isBoxed) + case expected @ CapturingType(eparent, refs) => + expected.derivedCapturingType(recur(eparent), refs) case expected @ defn.FunctionOf(args, resultType, isContextual) if defn.isNonRefinedFunction(expected) => actual match @@ -1369,6 +1381,14 @@ class CheckCaptures extends Recheck, SymTransformer: case _ => expected recur(expected) + private def unalignFunction(tp: Type)(using Context): Type = tp match + case tp @ CapturingType(parent, refs) => + tp.derivedCapturingType(unalignFunction(parent), refs) + case defn.RefinedFunctionOf(mt) => + mt.toFunctionType(alwaysDependent = false) + case _ => + tp + /** For the expected type, implement the rule outlined in #14390: * - when checking an expression `a: Ta^Ca` against an expected type `Te^Ce`, * - where the capture set `Ce` contains Cls.this, diff --git a/compiler/src/dotty/tools/dotc/cc/Setup.scala b/compiler/src/dotty/tools/dotc/cc/Setup.scala index 51ff6948a947..c8a3a023ea30 100644 --- a/compiler/src/dotty/tools/dotc/cc/Setup.scala +++ b/compiler/src/dotty/tools/dotc/cc/Setup.scala @@ -406,19 +406,26 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI: CapturingType(fntpe, cs, boxed = false) else fntpe - /** Check that types extending SharedCapability don't have a `cap` in their capture set. - * TODO This is not enough. - * We need to also track that we cannot get exclusive capabilities in paths - * where some prefix derives from SharedCapability. Also, can we just - * exclude `cap`, or do we have to extend this to all exclusive capabilties? - * The problem is that we know what is exclusive in general only after capture - * checking, not before. + /** 1. Check that parents of capturing types are not pure. + * 2. Check that types extending SharedCapability don't have a `cap` in their capture set. + * TODO This is not enough. + * We need to also track that we cannot get exclusive capabilities in paths + * where some prefix derives from SharedCapability. Also, can we just + * exclude `cap`, or do we have to extend this to all exclusive capabilties? + * The problem is that we know what is exclusive in general only after capture + * checking, not before. */ - def checkSharedOK(tp: Type): tp.type = + def checkRetainsOK(tp: Type): tp.type = tp match - case CapturingType(parent, refs) - if refs.isUniversal && parent.derivesFromSharedCapability => - fail(em"$tp extends SharedCapability, so it cannot capture `cap`") + case CapturingType(parent, refs) => + if parent.isAlwaysPure && !tptToCheck.span.isZeroExtent then + // If tptToCheck is zero-extent it could be copied from an overridden + // method's result type. In that case, there's no point requiring + // an explicit result type in the override, the inherited capture set + // will be ignored anyway. + fail(em"$parent is a pure type, it makes no sense to add a capture set to it") + else if refs.isUniversal && parent.derivesFromSharedCapability then + fail(em"$tp extends SharedCapability, so it cannot capture `cap`") case _ => tp @@ -436,7 +443,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI: def innerApply(t: Type) = t match case t @ CapturingType(parent, refs) => - checkSharedOK: + checkRetainsOK: t.derivedCapturingType(stripImpliedCaptureSet(this(parent)), refs) case t @ AnnotatedType(parent, ann) => val parent1 = this(parent) @@ -445,7 +452,7 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI: if !tptToCheck.isEmpty then checkWellformedLater(parent2, ann.tree, tptToCheck) try - checkSharedOK: + checkRetainsOK: CapturingType(parent2, ann.tree.toCaptureSet) catch case ex: IllegalCaptureRef => if !tptToCheck.isEmpty then diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index ea4626ac684e..fbda30bd52a0 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -1657,19 +1657,17 @@ object Types extends TypeUtils { NoType } - /** The iterator of underlying types as long as type is a TypeProxy. - * Useful for diagnostics + /** The iterator of underlying types staring with `this` and followed by + * repeatedly applying `f` as long as type is a TypeProxy. Useful for diagnostics. */ - def underlyingIterator(using Context): Iterator[Type] = new Iterator[Type] { + def iterate(f: TypeProxy => Type): Iterator[Type] = new Iterator[Type]: var current = Type.this var hasNext = true - def next() = { + def next() = val res = current hasNext = current.isInstanceOf[TypeProxy] - if (hasNext) current = current.asInstanceOf[TypeProxy].underlying + if hasNext then current = f(current.asInstanceOf[TypeProxy]) res - } - } /** A prefix-less refined this or a termRef to a new skolem symbol * that has the given type as info. diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index c8b2d0ad7add..f88e9bac4c73 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -282,7 +282,7 @@ class PlainPrinter(_ctx: Context) extends Printer { (" <: " ~ toText(bound) provided !bound.isAny) }.close case tp @ CapturingType(parent, refs) => - val boxText: Text = Str("box ") provided tp.isBoxed //&& ctx.settings.YccDebug.value + val boxText: Text = Str("box ") provided tp.isBoxed && ccVerbose if elideCapabilityCaps && parent.derivesFrom(defn.Caps_Capability) && refs.containsTerminalCapability diff --git a/scala2-library-cc/src/scala/collection/Iterable.scala b/scala2-library-cc/src/scala/collection/Iterable.scala index 6b6a03f88965..c5d10211e3ab 100644 --- a/scala2-library-cc/src/scala/collection/Iterable.scala +++ b/scala2-library-cc/src/scala/collection/Iterable.scala @@ -994,7 +994,7 @@ trait SortedSetFactoryDefaults[+A, +WithFilterCC[x] <: IterableOps[x, WithFilterCC, WithFilterCC[x]] with Set[x]] extends SortedSetOps[A @uncheckedVariance, CC, CC[A @uncheckedVariance]] { self: IterableOps[A, WithFilterCC, _] => - override protected def fromSpecific(coll: IterableOnce[A @uncheckedVariance]^): CC[A @uncheckedVariance]^{coll} = sortedIterableFactory.from(coll)(using ordering) + override protected def fromSpecific(coll: IterableOnce[A @uncheckedVariance]^): CC[A @uncheckedVariance] = sortedIterableFactory.from(coll)(using ordering) override protected def newSpecificBuilder: mutable.Builder[A @uncheckedVariance, CC[A @uncheckedVariance]] = sortedIterableFactory.newBuilder[A](using ordering) override def empty: CC[A @uncheckedVariance] = sortedIterableFactory.empty(using ordering) @@ -1050,7 +1050,7 @@ trait SortedMapFactoryDefaults[K, +V, self: IterableOps[(K, V), WithFilterCC, _] => override def empty: CC[K, V @uncheckedVariance] = sortedMapFactory.empty(using ordering) - override protected def fromSpecific(coll: IterableOnce[(K, V @uncheckedVariance)]^): CC[K, V @uncheckedVariance]^{coll} = sortedMapFactory.from(coll)(using ordering) + override protected def fromSpecific(coll: IterableOnce[(K, V @uncheckedVariance)]^): CC[K, V @uncheckedVariance] = sortedMapFactory.from(coll)(using ordering) override protected def newSpecificBuilder: mutable.Builder[(K, V @uncheckedVariance), CC[K, V @uncheckedVariance]] = sortedMapFactory.newBuilder[K, V](using ordering) override def withFilter(p: ((K, V)) => Boolean): collection.SortedMapOps.WithFilter[K, V, WithFilterCC, UnsortedCC, CC]^{p} = diff --git a/tests/neg-custom-args/captures/boundschecks3.check b/tests/neg-custom-args/captures/boundschecks3.check index 3121ee229cf6..51881f2a454f 100644 --- a/tests/neg-custom-args/captures/boundschecks3.check +++ b/tests/neg-custom-args/captures/boundschecks3.check @@ -1,23 +1,23 @@ -- [E057] Type Mismatch Error: tests/neg-custom-args/captures/boundschecks3.scala:9:11 --------------------------------- 9 | val foo: C[Tree^] = ??? // error | ^ - | Type argument box test.Tree^ does not conform to upper bound test.Tree in inferred type test.C[box test.Tree^] + | Type argument test.Tree^ does not conform to upper bound test.Tree in inferred type test.C[test.Tree^] | - | where: ^ refers to the universal root capability + | where: ^ refers to the universal root capability | | longer explanation available when compiling with `-explain` -- [E057] Type Mismatch Error: tests/neg-custom-args/captures/boundschecks3.scala:10:11 -------------------------------- 10 | type T = C[Tree^] // error | ^ - | Type argument box test.Tree^ does not conform to upper bound test.Tree in inferred type test.C[box test.Tree^] + | Type argument test.Tree^ does not conform to upper bound test.Tree in inferred type test.C[test.Tree^] | - | where: ^ refers to the universal root capability + | where: ^ refers to the universal root capability | | longer explanation available when compiling with `-explain` -- [E057] Type Mismatch Error: tests/neg-custom-args/captures/boundschecks3.scala:11:11 -------------------------------- 11 | val bar: T -> T = ??? // error | ^ - |Type argument box test.Tree^ does not conform to upper bound test.Tree in subpart test.C[box test.Tree^] of inferred type test.C[box test.Tree^] -> test.C[box test.Tree^] + |Type argument test.Tree^ does not conform to upper bound test.Tree in subpart test.C[test.Tree^] of inferred type test.C[test.Tree^] -> test.C[test.Tree^] | |where: ^ refers to the universal root capability | @@ -25,7 +25,7 @@ -- [E057] Type Mismatch Error: tests/neg-custom-args/captures/boundschecks3.scala:12:11 -------------------------------- 12 | val baz: C[Tree^] -> Unit = ??? // error | ^ - |Type argument box test.Tree^ does not conform to upper bound test.Tree in subpart test.C[box test.Tree^] of inferred type test.C[box test.Tree^] -> Unit + |Type argument test.Tree^ does not conform to upper bound test.Tree in subpart test.C[test.Tree^] of inferred type test.C[test.Tree^] -> Unit | |where: ^ refers to the universal root capability | diff --git a/tests/neg-custom-args/captures/box-adapt-cases.check b/tests/neg-custom-args/captures/box-adapt-cases.check index a3902a96994d..fc161baf341f 100644 --- a/tests/neg-custom-args/captures/box-adapt-cases.check +++ b/tests/neg-custom-args/captures/box-adapt-cases.check @@ -1,8 +1,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/box-adapt-cases.scala:8:10 ------------------------------- 8 | x.value(cap => cap.use()) // error, was OK | ^^^^^^^^^^^^^^^^ - | Found: (cap: box Cap^?) => Int - | Required: (cap: box Cap^) =>² Int + | Found: (cap: Cap^?) => Int + | Required: Cap^ =>² Int | | where: => refers to the universal root capability | =>² refers to a fresh root capability created in method test1 @@ -12,14 +12,14 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/box-adapt-cases.scala:15:10 ------------------------------ 15 | x.value(cap => cap.use()) // error | ^^^^^^^^^^^^^^^^ - | Found: (cap: box Cap^{io}) ->{io} Int - | Required: (cap: box Cap^{io}) -> Int + | Found: (cap: Cap^{io}) ->{io} Int + | Required: Cap^{io} -> Int | | longer explanation available when compiling with `-explain` -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/box-adapt-cases.scala:29:10 ------------------------------ 29 | x.value(cap => cap.use()) // error | ^^^^^^^^^^^^^^^^ - | Found: (cap: box Cap^?) ->{io, fs} Int - | Required: (cap: box Cap^{io, fs}) ->{io} Int + | Found: (cap: Cap^?) ->{io, fs} Int + | Required: Cap^{io, fs} ->{io} Int | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/box-adapt-contra.check b/tests/neg-custom-args/captures/box-adapt-contra.check index b0bdc1d51ce1..a598656743fc 100644 --- a/tests/neg-custom-args/captures/box-adapt-contra.check +++ b/tests/neg-custom-args/captures/box-adapt-contra.check @@ -1,18 +1,18 @@ -- Error: tests/neg-custom-args/captures/box-adapt-contra.scala:9:52 --------------------------------------------------- 9 | val f: (Cap^{c} -> Unit) -> Unit = useCap[Cap^{c}](c) // error | ^^^^^^^^^^^^^^^^^^ - | Cap^{c} -> Unit cannot be box-converted to box Cap^{c} ->{c} Unit - | since the additional capture set {c} resulting from box conversion is not allowed in box Cap^{c} -> Unit + | Cap^{c} -> Unit cannot be box-converted to Cap^{c} ->{c} Unit + | since the additional capture set {c} resulting from box conversion is not allowed in Cap^{c} -> Unit -- Error: tests/neg-custom-args/captures/box-adapt-contra.scala:13:57 -------------------------------------------------- 13 | val f1: (Cap^{c} => Unit) ->{c} Unit = useCap1[Cap^{c}](c) // error, was ok when cap was a root | ^^^^^^^^^^^^^^^^^^^ - | Cap^{c} => Unit cannot be box-converted to box Cap^{c} ->{cap, c} Unit - | since the additional capture set {c} resulting from box conversion is not allowed in box Cap^{c} => Unit + | Cap^{c} => Unit cannot be box-converted to Cap^{c} ->{cap, c} Unit + | since the additional capture set {c} resulting from box conversion is not allowed in Cap^{c} => Unit | - | where: => refers to the universal root capability - | cap is the universal root capability + | where: => refers to the universal root capability + | cap is the universal root capability -- Error: tests/neg-custom-args/captures/box-adapt-contra.scala:19:54 -------------------------------------------------- 19 | val f3: (Cap^{c} -> Unit) => Unit = useCap3[Cap^{c}](c) // error | ^^^^^^^^^^^^^^^^^^^ - | Cap^{c} -> Unit cannot be box-converted to box Cap^{c} ->{d, c} Unit - | since the additional capture set {c} resulting from box conversion is not allowed in box Cap^{c} ->{d} Unit + | Cap^{c} -> Unit cannot be box-converted to Cap^{c} ->{d, c} Unit + | since the additional capture set {c} resulting from box conversion is not allowed in Cap^{c} ->{d} Unit diff --git a/tests/neg-custom-args/captures/capt1.check b/tests/neg-custom-args/captures/capt1.check index 68047cb32429..5c1008190886 100644 --- a/tests/neg-custom-args/captures/capt1.check +++ b/tests/neg-custom-args/captures/capt1.check @@ -40,15 +40,15 @@ -- Error: tests/neg-custom-args/captures/capt1.scala:36:16 ------------------------------------------------------------- 36 | val z2 = h[() -> Cap](() => x) // error // error | ^^^^^^^^^ - | Type variable X of method h cannot be instantiated to () -> box C^ since - | the part box C^ of that type captures the root capability `cap`. + | Type variable X of method h cannot be instantiated to () -> C^ since + | the part C^ of that type captures the root capability `cap`. | | where: ^ refers to the universal root capability -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/capt1.scala:36:24 ---------------------------------------- 36 | val z2 = h[() -> Cap](() => x) // error // error | ^^^^^^^ - |Found: () ->{x} box C^{x} - |Required: () -> box C^ + |Found: () ->{x} C^{x} + |Required: () -> C^ | |where: ^ refers to a fresh root capability created in value z2 when checking argument to parameter a of method h | @@ -56,7 +56,7 @@ -- Error: tests/neg-custom-args/captures/capt1.scala:38:13 ------------------------------------------------------------- 38 | val z3 = h[(() -> Cap) @retains[x.type]](() => x)(() => C()) // error | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | Type variable X of method h cannot be instantiated to box () ->{x} C^ since + | Type variable X of method h cannot be instantiated to () ->{x} C^ since | the part C^ of that type captures the root capability `cap`. | | where: ^ refers to the universal root capability diff --git a/tests/neg-custom-args/captures/delayedRunops.check b/tests/neg-custom-args/captures/delayedRunops.check index 4e2fb9525e8f..c4e5f7ab7a8a 100644 --- a/tests/neg-custom-args/captures/delayedRunops.check +++ b/tests/neg-custom-args/captures/delayedRunops.check @@ -11,4 +11,4 @@ -- Error: tests/neg-custom-args/captures/delayedRunops.scala:22:16 ----------------------------------------------------- 22 | val ops1: List[() => Unit] = ops // error | ^^^^^^^^^^^^^^^^ - | Separation failure: value ops1's type List[box () => Unit] hides non-local parameter ops + | Separation failure: value ops1's type List[() => Unit] hides non-local parameter ops diff --git a/tests/neg-custom-args/captures/depfun-reach.check b/tests/neg-custom-args/captures/depfun-reach.check index 9f47722078aa..b051de4d0eb4 100644 --- a/tests/neg-custom-args/captures/depfun-reach.check +++ b/tests/neg-custom-args/captures/depfun-reach.check @@ -1,8 +1,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/depfun-reach.scala:12:27 --------------------------------- 12 | List(() => op.foreach((f,g) => { f(); g() })) // error (???) | ^^^^^^^^^^^^^^^^^^^^ - |Found: (x$1: (box () ->? Unit, box () ->? Unit)^?) ->? Unit - |Required: (x$1: (box () ->{op*} Unit, box () ->{op*} Unit)) => Unit + |Found: (x$1: (() ->? Unit, () ->? Unit)^?) ->? Unit + |Required: ((() ->{op*} Unit, () ->{op*} Unit)) => Unit | |where: => refers to a fresh root capability created in anonymous function of type (): Unit when checking argument to parameter op of method foreach | @@ -10,8 +10,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/depfun-reach.scala:19:4 ---------------------------------- 19 | op // error | ^^ - | Found: (op : (xs: List[(X, box () ->{io} Unit)]) => List[box () ->{xs*} Unit]) - | Required: (xs: List[(X, box () ->{io} Unit)]) =>² List[() -> Unit] + | Found: (op : (xs: List[(X, () ->{io} Unit)]) => List[() ->{xs*} Unit]) + | Required: (xs: List[(X, () ->{io} Unit)]) =>² List[() -> Unit] | | where: => refers to a fresh root capability in the type of parameter op | =>² refers to a fresh root capability in the result type of method foo @@ -20,15 +20,15 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/depfun-reach.scala:26:60 --------------------------------- 26 | val b: (xs: List[() ->{io} Unit]) => List[() ->{} Unit] = a // error | ^ - | Found: (a : (xs: List[box () ->{io} Unit]) => List[box () ->{xs*} Unit]) - | Required: (xs: List[box () ->{io} Unit]) =>² List[() -> Unit] + | Found: (a : (xs: List[() ->{io} Unit]) => List[() ->{xs*} Unit]) + | Required: (xs: List[() ->{io} Unit]) =>² List[() -> Unit] | - | where: => refers to a fresh root capability in the type of value a - | =>² refers to a fresh root capability in the type of value b + | where: => refers to a fresh root capability in the type of value a + | =>² refers to a fresh root capability in the type of value b | | longer explanation available when compiling with `-explain` -- Error: tests/neg-custom-args/captures/depfun-reach.scala:18:17 ------------------------------------------------------ 18 | : (xs: List[(X, () ->{io} Unit)]) => List[() ->{} Unit] = // error | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - |Separation failure: method foo's result type (xs: List[(X, box () ->{io} Unit)]) => List[() -> Unit] hides parameter op. + |Separation failure: method foo's result type (xs: List[(X, () ->{io} Unit)]) => List[() -> Unit] hides parameter op. |The parameter needs to be annotated with @consume to allow this. diff --git a/tests/neg-custom-args/captures/effect-swaps-explicit.check b/tests/neg-custom-args/captures/effect-swaps-explicit.check index 469a0c6f14a4..cc53b051e462 100644 --- a/tests/neg-custom-args/captures/effect-swaps-explicit.check +++ b/tests/neg-custom-args/captures/effect-swaps-explicit.check @@ -2,7 +2,7 @@ 63 | Result: 64 | Future: // error, type mismatch | ^ - | Found: Result.Ok[box Future[box T^?]^{fr, contextual$1}] + | Found: Result.Ok[Future[T^?]^{fr, contextual$1}] | Required: Result[Future[T], Nothing] 65 | fr.await.ok |-------------------------------------------------------------------------------------------------------------------- @@ -17,23 +17,22 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/effect-swaps-explicit.scala:69:10 ------------------------ 69 | Future: fut ?=> // error, type mismatch | ^ - |Found: (contextual$9: boundary.Label[box Result[box Future[box T^?]^?, box E^?]^?]^) ?->{fr, async} - | box Future[box T^?]^{fr, contextual$9} - |Required: (contextual$9: boundary.Label[Result[box Future[box T^?]^?, box E^?]]^) ?=> box Future[box T^?]^? + |Found: (contextual$9: boundary.Label[Result[Future[T^?]^?, E^?]^?]^) ?->{fr, async} Future[T^?]^{fr, contextual$9} + |Required: (boundary.Label[Result[Future[T^?]^{fr, async}, E^?]]^) ?=> Future[T^?]^{fr, async} | |where: ?=> refers to a fresh root capability created in method fail4 when checking argument to parameter body of method make | ^ refers to the universal root capability | |Note that reference contextual$9.type - |cannot be included in outer capture set ? + |cannot be included in outer capture set {fr, async} 70 | fr.await.ok | | longer explanation available when compiling with `-explain` -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/effect-swaps-explicit.scala:73:35 ------------------------ 73 | Result.make[Future[T], E]: lbl ?=> // error: type mismatch | ^ - |Found: (lbl: boundary.Label[box Result[box Future[box T^?]^?, box E^?]^?]^) ?->{fr, async} Future[box T^?]^{fr, lbl} - |Required: (lbl: boundary.Label[Result[Future[T], E]]^) ?=> Future[T] + |Found: (lbl: boundary.Label[Result[Future[T^?]^?, E^?]^?]^) ?->{fr, async} Future[T^?]^{fr, lbl} + |Required: (boundary.Label[Result[Future[T], E]]^) ?=> Future[T] | |where: ?=> refers to a fresh root capability created in method fail5 when checking argument to parameter body of method make | ^ refers to the universal root capability diff --git a/tests/neg-custom-args/captures/effect-swaps.check b/tests/neg-custom-args/captures/effect-swaps.check index 69cedcde2f75..e6c7315fc177 100644 --- a/tests/neg-custom-args/captures/effect-swaps.check +++ b/tests/neg-custom-args/captures/effect-swaps.check @@ -2,7 +2,7 @@ 63 | Result: 64 | Future: // error, type mismatch | ^ - | Found: Result.Ok[box Future[box T^?]^{fr, contextual$1}] + | Found: Result.Ok[Future[T^?]^{fr, contextual$1}] | Required: Result[Future[T], Nothing] 65 | fr.await.ok |-------------------------------------------------------------------------------------------------------------------- @@ -17,23 +17,22 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/effect-swaps.scala:69:10 --------------------------------- 69 | Future: fut ?=> // error, type mismatch | ^ - |Found: (contextual$9: boundary.Label[box Result[box Future[box T^?]^?, box E^?]^?]^{cap.rd}) ?->{fr, async} - | box Future[box T^?]^{fr, contextual$9} - |Required: (contextual$9: boundary.Label[Result[box Future[box T^?]^?, box E^?]]^{cap.rd}) ?=> box Future[box T^?]^? + |Found: (contextual$9: boundary.Label[Result[Future[T^?]^?, E^?]^?]^{cap.rd}) ?->{fr, async} Future[T^?]^{fr, contextual$9} + |Required: (boundary.Label[Result[Future[T^?]^{fr, async}, E^?]]^{cap.rd}) ?=> Future[T^?]^{fr, async} | |where: ?=> refers to a fresh root capability created in method fail4 when checking argument to parameter body of method make | cap is the universal root capability | |Note that reference contextual$9.type - |cannot be included in outer capture set ? + |cannot be included in outer capture set {fr, async} 70 | fr.await.ok | | longer explanation available when compiling with `-explain` -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/effect-swaps.scala:73:35 --------------------------------- 73 | Result.make[Future[T], E]: lbl ?=> // error: type mismatch | ^ - |Found: (lbl: boundary.Label[box Result[box Future[box T^?]^?, box E^?]^?]^{cap.rd}) ?->{fr, async} Future[box T^?]^{fr, lbl} - |Required: (lbl: boundary.Label[Result[Future[T], E]]^{cap.rd}) ?=> Future[T] + |Found: (lbl: boundary.Label[Result[Future[T^?]^?, E^?]^?]^{cap.rd}) ?->{fr, async} Future[T^?]^{fr, lbl} + |Required: (boundary.Label[Result[Future[T], E]]^{cap.rd}) ?=> Future[T] | |where: ?=> refers to a fresh root capability created in method fail5 when checking argument to parameter body of method make | cap is the universal root capability diff --git a/tests/neg-custom-args/captures/eta.check b/tests/neg-custom-args/captures/eta.check index d658adcad17b..9b74a86d3b49 100644 --- a/tests/neg-custom-args/captures/eta.check +++ b/tests/neg-custom-args/captures/eta.check @@ -8,7 +8,7 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/eta.scala:6:14 ------------------------------------------- 6 | bar( () => f ) // error | ^^^^^^^ - | Found: () ->{f} box () ->{f} Unit - | Required: () -> box () ->? Unit + | Found: () ->{f} () ->{f} Unit + | Required: () -> () ->? Unit | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/exception-definitions.check b/tests/neg-custom-args/captures/exception-definitions.check index 67f0f3b72cbb..be5ea4304bf5 100644 --- a/tests/neg-custom-args/captures/exception-definitions.check +++ b/tests/neg-custom-args/captures/exception-definitions.check @@ -1,7 +1,7 @@ -- Error: tests/neg-custom-args/captures/exception-definitions.scala:3:8 ----------------------------------------------- 3 | self: Err^ => // error | ^^^^ - |reference cap captured by this self type is not included in the allowed capture set {} of pure base class class Throwable + | Err is a pure type, it makes no sense to add a capture set to it -- Error: tests/neg-custom-args/captures/exception-definitions.scala:7:12 ---------------------------------------------- 7 | val x = c // error | ^ diff --git a/tests/neg-custom-args/captures/existential-mapping.check b/tests/neg-custom-args/captures/existential-mapping.check index 9be0f250e47f..a867be0d8f7a 100644 --- a/tests/neg-custom-args/captures/existential-mapping.check +++ b/tests/neg-custom-args/captures/existential-mapping.check @@ -1,7 +1,7 @@ -- Error: tests/neg-custom-args/captures/existential-mapping.scala:46:10 ----------------------------------------------- 46 | val z2: (x: A^) => Array[C^] = ??? // error | ^^^^^^^^^^^^^^^^^^^^ - | Array[box C^] captures the root capability `cap` in invariant position. + | Array[C^] captures the root capability `cap` in invariant position. | This capability cannot be converted to an existential in the result type of a function. | | where: ^ refers to the universal root capability diff --git a/tests/neg-custom-args/captures/gears-problem.check b/tests/neg-custom-args/captures/gears-problem.check index 1c3e648a6264..0fc5f8c3f163 100644 --- a/tests/neg-custom-args/captures/gears-problem.check +++ b/tests/neg-custom-args/captures/gears-problem.check @@ -8,7 +8,7 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/gears-problem.scala:24:34 -------------------------------- 24 | val fut2: Future[T]^{fs*} = r.get // error | ^^^^^ - | Found: Future[box T^{}]^{collector.futures*} + | Found: Future[T^{}]^{collector.futures*} | Required: Future[T]^{fs*} | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/heal-tparam-cs.check b/tests/neg-custom-args/captures/heal-tparam-cs.check index 0a7c333c9e95..2a9aeb5d2ae2 100644 --- a/tests/neg-custom-args/captures/heal-tparam-cs.check +++ b/tests/neg-custom-args/captures/heal-tparam-cs.check @@ -1,8 +1,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/heal-tparam-cs.scala:10:23 ------------------------------- 10 | val test1 = localCap { c => // error | ^ - |Found: (c: Capp^) ->? box () ->{c} Unit - |Required: (c: Capp^) => box () ->? Unit + |Found: (c: Capp^) ->? () ->{c} Unit + |Required: (c: Capp^) => () ->? Unit | |where: => refers to a fresh root capability created in value test1 when checking argument to parameter op of method localCap | ^ refers to the universal root capability @@ -50,7 +50,7 @@ 44 | io => () => io.use() // error | ^^^^^^^^^^^^^^^^^^^^ | Found: (io: Capp^) ->? () ->{io} Unit - | Required: (io: Capp^) -> () -> Unit + | Required: Capp^ -> () -> Unit | | where: ^ refers to the universal root capability | diff --git a/tests/neg-custom-args/captures/i15116.check b/tests/neg-custom-args/captures/i15116.check index 50784d393162..462c1b6ed89b 100644 --- a/tests/neg-custom-args/captures/i15116.check +++ b/tests/neg-custom-args/captures/i15116.check @@ -1,72 +1,48 @@ --- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15116.scala:3:13 ---------------------------------------- -3 | val x = Foo(m) // error - | ^^^^^^ - | Found: Foo{val m: (Bar.this.m² : String^)}^{Bar.this.m²} - | Required: Foo - | - | where: ^ refers to a fresh root capability in the type of value m² - | m is a value in class Foo - | m² is a value in class Bar - | - | - | Note that the expected type Foo - | is the previously inferred type of value x - | which is also the type seen in separately compiled sources. - | The new inferred type Foo{val m: (Bar.this.m : String^)}^{Bar.this.m} - | must conform to this type. - | - | longer explanation available when compiling with `-explain` --- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15116.scala:5:13 ---------------------------------------- +-- Error: tests/neg-custom-args/captures/i15116.scala:5:13 ------------------------------------------------------------- 5 | val x = Foo(m) // error | ^^^^^^ - | Found: Foo{val m: (Baz.this.m² : String^)}^{Baz.this.m²} - | Required: Foo + | value x needs an explicit type because the inferred type does not conform to + | the type that is externally visible in other compilation units. + | + | Inferred type : test.Foo{val m: (Bar.this.m² : test.STR^)}^{Bar.this.m²} + | Externally visible type: test.Foo | | where: ^ refers to a fresh root capability in the type of value m² | m is a value in class Foo - | m² is a value in trait Baz - | - | - | Note that the expected type Foo - | is the previously inferred type of value x - | which is also the type seen in separately compiled sources. - | The new inferred type Foo{val m: (Baz.this.m : String^)}^{Baz.this.m} - | must conform to this type. - | - | longer explanation available when compiling with `-explain` --- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15116.scala:7:13 ---------------------------------------- + | m² is a value in class Bar +-- Error: tests/neg-custom-args/captures/i15116.scala:7:13 ------------------------------------------------------------- 7 | val x = Foo(m) // error | ^^^^^^ - | Found: Foo{val m: (Bar1.this.m² : String^)}^{Bar1.this.m²} - | Required: Foo + | value x needs an explicit type because the inferred type does not conform to + | the type that is externally visible in other compilation units. + | + | Inferred type : test.Foo{val m: (Baz.this.m² : test.STR^)}^{Baz.this.m²} + | Externally visible type: test.Foo | | where: ^ refers to a fresh root capability in the type of value m² | m is a value in class Foo - | m² is a value in class Bar1 - | - | - | Note that the expected type Foo - | is the previously inferred type of value x - | which is also the type seen in separately compiled sources. - | The new inferred type Foo{val m: (Bar1.this.m : String^)}^{Bar1.this.m} - | must conform to this type. - | - | longer explanation available when compiling with `-explain` --- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15116.scala:9:13 ---------------------------------------- + | m² is a value in trait Baz +-- Error: tests/neg-custom-args/captures/i15116.scala:9:13 ------------------------------------------------------------- 9 | val x = Foo(m) // error | ^^^^^^ - | Found: Foo{val m: (Baz2.this.m² : String^)}^{Baz2.this.m²} - | Required: Foo + | value x needs an explicit type because the inferred type does not conform to + | the type that is externally visible in other compilation units. + | + | Inferred type : test.Foo{val m: (Bar1.this.m² : test.STR^)}^{Bar1.this.m²} + | Externally visible type: test.Foo | | where: ^ refers to a fresh root capability in the type of value m² | m is a value in class Foo - | m² is a value in trait Baz2 - | - | - | Note that the expected type Foo - | is the previously inferred type of value x - | which is also the type seen in separately compiled sources. - | The new inferred type Foo{val m: (Baz2.this.m : String^)}^{Baz2.this.m} - | must conform to this type. - | - | longer explanation available when compiling with `-explain` + | m² is a value in class Bar1 +-- Error: tests/neg-custom-args/captures/i15116.scala:11:13 ------------------------------------------------------------ +11 | val x = Foo(m) // error + | ^^^^^^ + | value x needs an explicit type because the inferred type does not conform to + | the type that is externally visible in other compilation units. + | + | Inferred type : test.Foo{val m: (Baz2.this.m² : test.STR^)}^{Baz2.this.m²} + | Externally visible type: test.Foo + | + | where: ^ refers to a fresh root capability in the type of value m² + | m is a value in class Foo + | m² is a value in trait Baz2 diff --git a/tests/neg-custom-args/captures/i15116.scala b/tests/neg-custom-args/captures/i15116.scala index c4dc6c88d56c..d7265646782b 100644 --- a/tests/neg-custom-args/captures/i15116.scala +++ b/tests/neg-custom-args/captures/i15116.scala @@ -1,9 +1,11 @@ -class Foo(m: String^) -class Bar(val m: String^): +package test +class STR +class Foo(m: STR^) +class Bar(val m: STR^): val x = Foo(m) // error -trait Baz(val m: String^): +trait Baz(val m: STR^): val x = Foo(m) // error -class Bar1(m: String^): +class Bar1(m: STR^): val x = Foo(m) // error -trait Baz2(m: String^): +trait Baz2(m: STR^): val x = Foo(m) // error diff --git a/tests/neg-custom-args/captures/i15772.check b/tests/neg-custom-args/captures/i15772.check index 4e0db9606fe4..8c71937090ed 100644 --- a/tests/neg-custom-args/captures/i15772.check +++ b/tests/neg-custom-args/captures/i15772.check @@ -1,8 +1,8 @@ -- Error: tests/neg-custom-args/captures/i15772.scala:22:46 ------------------------------------------------------------ 22 | val boxed1 : ((C^) => Unit) -> Unit = box1(c) // error | ^^^^^^^ - |C^ => Unit cannot be box-converted to box C{val arg: C^²}^{c} ->{cap, c} Unit - |since the additional capture set {c} resulting from box conversion is not allowed in box C{val arg: C^²}^{c} => Unit + |C^ => Unit cannot be box-converted to C{val arg: C^²}^{c} ->{cap, c} Unit + |since the additional capture set {c} resulting from box conversion is not allowed in C{val arg: C^²}^{c} => Unit | |where: => refers to the universal root capability | ^ refers to the universal root capability @@ -11,8 +11,8 @@ -- Error: tests/neg-custom-args/captures/i15772.scala:29:35 ------------------------------------------------------------ 29 | val boxed2 : Observe[C^] = box2(c) // error | ^^^^^^^ - |C^ => Unit cannot be box-converted to box C{val arg: C^²}^{c} ->{cap, c} Unit - |since the additional capture set {c} resulting from box conversion is not allowed in box C{val arg: C^²}^{c} => Unit + |C^ => Unit cannot be box-converted to C{val arg: C^²}^{c} ->{cap, c} Unit + |since the additional capture set {c} resulting from box conversion is not allowed in C{val arg: C^²}^{c} => Unit | |where: => refers to the universal root capability | ^ refers to the universal root capability diff --git a/tests/neg-custom-args/captures/i15923.check b/tests/neg-custom-args/captures/i15923.check index 4d3019f92d7a..39e80e0090a5 100644 --- a/tests/neg-custom-args/captures/i15923.check +++ b/tests/neg-custom-args/captures/i15923.check @@ -1,14 +1,14 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15923.scala:12:21 --------------------------------------- 12 | val leak = withCap(cap => mkId(cap)) // error | ^^^^^^^^^^^^^^^^ - |Found: (lcap: scala.caps.Capability^{cap.rd}) ?->? Cap^{lcap} ->? box Id[box Cap^{cap².rd}]^? - |Required: (lcap: scala.caps.Capability^{cap.rd}) ?-> Cap^{lcap} => box Id[box Cap^?]^? + |Found: (lcap: scala.caps.Capability^{cap.rd}) ?->? Cap^{lcap} ->? Id[Cap^{cap².rd}]^? + |Required: (lcap: scala.caps.Capability^{cap.rd}) ?-> Cap^{lcap} => Id[Cap^?]^? | - |where: => refers to a root capability associated with the result type of (using lcap: scala.caps.Capability^{cap.rd}): Cap^{lcap} => box Id[box Cap^?]^? + |where: => refers to a root capability associated with the result type of (using lcap: scala.caps.Capability^{cap.rd}): Cap^{lcap} => Id[Cap^?]^? | cap is the universal root capability - | cap² is a root capability associated with the result type of (x$0: Cap^{lcap}): box Id[box Cap^{cap².rd}]^? + | cap² is a root capability associated with the result type of (x$0: Cap^{lcap}): Id[Cap^{cap².rd}]^? | - |Note that reference .rd + |Note that reference .rd |cannot be included in outer capture set ? | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/i15923a.check b/tests/neg-custom-args/captures/i15923a.check index 1b4ef98aff20..c93a54144e27 100644 --- a/tests/neg-custom-args/captures/i15923a.check +++ b/tests/neg-custom-args/captures/i15923a.check @@ -1,15 +1,15 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15923a.scala:7:21 --------------------------------------- 7 | val leak = withCap(lcap => () => mkId(lcap)) // error | ^^^^^^^^^^^^^^^^^^^^^^^^ - |Found: (lcap: Cap^) ->? () ->? box Id[box Cap^²]^? - |Required: (lcap: Cap^) => () =>² box Id[box Cap^?]^? + |Found: (lcap: Cap^) ->? () ->? Id[Cap^²]^? + |Required: (lcap: Cap^) => () =>² Id[Cap^?]^? | |where: => refers to a fresh root capability created in value leak when checking argument to parameter op of method withCap - | =>² refers to a root capability associated with the result type of (lcap: Cap^): () =>² box Id[box Cap^?]^? + | =>² refers to a root capability associated with the result type of (lcap: Cap^): () =>² Id[Cap^?]^? | ^ refers to the universal root capability - | ^² refers to a root capability associated with the result type of (): box Id[box Cap^²]^? + | ^² refers to a root capability associated with the result type of (): Id[Cap^²]^? | - |Note that reference + |Note that reference |cannot be included in outer capture set ? | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/i15923b.check b/tests/neg-custom-args/captures/i15923b.check index eb67188bcc25..c7825851a7ef 100644 --- a/tests/neg-custom-args/captures/i15923b.check +++ b/tests/neg-custom-args/captures/i15923b.check @@ -1,8 +1,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15923b.scala:8:21 --------------------------------------- 8 | val leak = withCap(f) // error | ^ - |Found: (x$0: Cap^) -> Id[box Cap^{x$0}] - |Required: (lcap: Cap^) => box Id[box Cap^?]^? + |Found: (x$0: Cap^) -> Id[Cap^{x$0}] + |Required: (lcap: Cap^) => Id[Cap^?]^? | |where: => refers to a fresh root capability created in value leak when checking argument to parameter op of method withCap | ^ refers to the universal root capability diff --git a/tests/neg-custom-args/captures/i16114.check b/tests/neg-custom-args/captures/i16114.check index b83631660b9d..5e755d6770f1 100644 --- a/tests/neg-custom-args/captures/i16114.check +++ b/tests/neg-custom-args/captures/i16114.check @@ -1,35 +1,35 @@ -- Error: tests/neg-custom-args/captures/i16114.scala:18:13 ------------------------------------------------------------ 18 | expect[Cap^] { // error | ^^^^ - | Type variable T of method expect cannot be instantiated to box Cap^ since + | Type variable T of method expect cannot be instantiated to Cap^ since | that type captures the root capability `cap`. | | where: ^ refers to the universal root capability -- Error: tests/neg-custom-args/captures/i16114.scala:24:13 ------------------------------------------------------------ 24 | expect[Cap^] { // error | ^^^^ - | Type variable T of method expect cannot be instantiated to box Cap^ since + | Type variable T of method expect cannot be instantiated to Cap^ since | that type captures the root capability `cap`. | | where: ^ refers to the universal root capability -- Error: tests/neg-custom-args/captures/i16114.scala:30:13 ------------------------------------------------------------ 30 | expect[Cap^] { // error | ^^^^ - | Type variable T of method expect cannot be instantiated to box Cap^ since + | Type variable T of method expect cannot be instantiated to Cap^ since | that type captures the root capability `cap`. | | where: ^ refers to the universal root capability -- Error: tests/neg-custom-args/captures/i16114.scala:36:13 ------------------------------------------------------------ 36 | expect[Cap^](io) // error | ^^^^ - | Type variable T of method expect cannot be instantiated to box Cap^ since + | Type variable T of method expect cannot be instantiated to Cap^ since | that type captures the root capability `cap`. | | where: ^ refers to the universal root capability -- Error: tests/neg-custom-args/captures/i16114.scala:39:13 ------------------------------------------------------------ 39 | expect[Cap^] { // error | ^^^^ - | Type variable T of method expect cannot be instantiated to box Cap^ since + | Type variable T of method expect cannot be instantiated to Cap^ since | that type captures the root capability `cap`. | | where: ^ refers to the universal root capability diff --git a/tests/neg-custom-args/captures/i16226.check b/tests/neg-custom-args/captures/i16226.check index 4fb4119fdbef..283a413813cc 100644 --- a/tests/neg-custom-args/captures/i16226.check +++ b/tests/neg-custom-args/captures/i16226.check @@ -1,11 +1,11 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i16226.scala:13:4 ---------------------------------------- 13 | (ref1, f1) => map[A, B](ref1, f1) // error | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - |Found: (ref1: LazyRef[box A^?]{val elem: () => A^?}^{io}, f1: A^? => B^?) ->? LazyRef[box B^?]{val elem: () =>² B^?}^{f1, ref1} - |Required: (ref1: LazyRef[A]^{io}, f1: A => B) =>³ LazyRef[B]^ + |Found: (ref1: LazyRef[A^?]{val elem: () => A^?}^{io}, f1: A^? => B^?) ->? LazyRef[B^?]{val elem: () =>² B^?}^{f1, ref1} + |Required: (LazyRef[A]^{io}, A => B) =>³ LazyRef[B]^ | |where: => refers to the universal root capability - | =>² refers to a root capability associated with the result type of (ref1: LazyRef[box A^?]{val elem: () => A^?}^{io}, f1: A^? => B^?): LazyRef[box B^?]{val elem: () =>² B^?}^{f1, ref1} + | =>² refers to a root capability associated with the result type of (ref1: LazyRef[A^?]{val elem: () => A^?}^{io}, f1: A^? => B^?): LazyRef[B^?]{val elem: () =>² B^?}^{f1, ref1} | =>³ refers to a fresh root capability in the result type of method mapc | ^ refers to a fresh root capability in the result type of method mapc | @@ -13,11 +13,11 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i16226.scala:15:4 ---------------------------------------- 15 | (ref1, f1) => map[A, B](ref1, f1) // error | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - |Found: (ref1: LazyRef[box A^?]{val elem: () => A^?}^{io}, f1: A^? => B^?) ->? LazyRef[box B^?]{val elem: () =>² B^?}^{f1, ref1} + |Found: (ref1: LazyRef[A^?]{val elem: () => A^?}^{io}, f1: A^? => B^?) ->? LazyRef[B^?]{val elem: () =>² B^?}^{f1, ref1} |Required: (ref: LazyRef[A]^{io}, f: A => B) =>³ LazyRef[B]^ | |where: => refers to the universal root capability - | =>² refers to a root capability associated with the result type of (ref1: LazyRef[box A^?]{val elem: () => A^?}^{io}, f1: A^? => B^?): LazyRef[box B^?]{val elem: () =>² B^?}^{f1, ref1} + | =>² refers to a root capability associated with the result type of (ref1: LazyRef[A^?]{val elem: () => A^?}^{io}, f1: A^? => B^?): LazyRef[B^?]{val elem: () =>² B^?}^{f1, ref1} | =>³ refers to a fresh root capability in the result type of method mapd | ^ refers to a root capability associated with the result type of (ref: LazyRef[A]^{io}, f: A => B): LazyRef[B]^ | diff --git a/tests/neg-custom-args/captures/i19470.check b/tests/neg-custom-args/captures/i19470.check index 68eba72c92bd..745018c54c88 100644 --- a/tests/neg-custom-args/captures/i19470.check +++ b/tests/neg-custom-args/captures/i19470.check @@ -1,7 +1,7 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i19470.scala:9:12 ---------------------------------------- 9 | List(foo(f())) // error | ^^^^^^^^ - | Found: Inv[box IO^{f?}] - | Required: box Inv[box IO^?]^? + | Found: Inv[IO^{f?}] + | Required: Inv[IO^?]^? | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/i21401.check b/tests/neg-custom-args/captures/i21401.check index 2f0443e90ed9..7e06a0edc75a 100644 --- a/tests/neg-custom-args/captures/i21401.check +++ b/tests/neg-custom-args/captures/i21401.check @@ -1,22 +1,22 @@ -- Error: tests/neg-custom-args/captures/i21401.scala:13:14 ------------------------------------------------------------ 13 | op1(Boxed[IO^](x)) // error | ^^^ - | Type variable T of object Boxed cannot be instantiated to box IO^ since + | Type variable T of object Boxed cannot be instantiated to IO^ since | that type captures the root capability `cap`. | | where: ^ refers to the universal root capability -- Error: tests/neg-custom-args/captures/i21401.scala:15:18 ------------------------------------------------------------ 15 | val a = usingIO[IO^](x => x) // error // error | ^^^ - | Type variable R of method usingIO cannot be instantiated to box IO^ since + | Type variable R of method usingIO cannot be instantiated to IO^ since | that type captures the root capability `cap`. | | where: ^ refers to the universal root capability -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i21401.scala:15:23 --------------------------------------- 15 | val a = usingIO[IO^](x => x) // error // error | ^^^^^^ - |Found: (x: IO^) ->? box IO^{x} - |Required: (x: IO^) => box IO^² + |Found: (x: IO^) ->? IO^{x} + |Required: IO^ => IO^² | |where: => refers to a fresh root capability created in value a when checking argument to parameter op of method usingIO | ^ refers to the universal root capability @@ -26,29 +26,29 @@ -- Error: tests/neg-custom-args/captures/i21401.scala:16:66 ------------------------------------------------------------ 16 | val leaked: [R, X <: Boxed[IO^] -> R] -> (op: X) -> R = usingIO[Res](mkRes) // error | ^^^ - | Type variable R of method usingIO cannot be instantiated to [R, X <: Boxed[box IO^] -> R] => (op: X) -> R since - | the part box IO^ of that type captures the root capability `cap`. + | Type variable R of method usingIO cannot be instantiated to [R, X <: Boxed[IO^] -> R] => (op: X) -> R since + | the part IO^ of that type captures the root capability `cap`. | - | where: ^ refers to the universal root capability + | where: ^ refers to the universal root capability -- Error: tests/neg-custom-args/captures/i21401.scala:17:29 ------------------------------------------------------------ 17 | val x: Boxed[IO^] = leaked[Boxed[IO^], Boxed[IO^] -> Boxed[IO^]](x => x) // error // error // error | ^^^^^^^^^^ - | Type variable R of value leaked cannot be instantiated to Boxed[box IO^] since - | the part box IO^ of that type captures the root capability `cap`. + | Type variable R of value leaked cannot be instantiated to Boxed[IO^] since + | the part IO^ of that type captures the root capability `cap`. | | where: ^ refers to the universal root capability -- Error: tests/neg-custom-args/captures/i21401.scala:17:52 ------------------------------------------------------------ 17 | val x: Boxed[IO^] = leaked[Boxed[IO^], Boxed[IO^] -> Boxed[IO^]](x => x) // error // error // error | ^^^^^^^^^^^^^^^^^^^^^^^^ - | Type variable X of value leaked cannot be instantiated to Boxed[box IO^] -> Boxed[box IO^] since - | the part box IO^ of that type captures the root capability `cap`. + | Type variable X of value leaked cannot be instantiated to Boxed[IO^] -> Boxed[IO^] since + | the part IO^ of that type captures the root capability `cap`. | - | where: ^ refers to the universal root capability + | where: ^ refers to the universal root capability -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i21401.scala:17:67 --------------------------------------- 17 | val x: Boxed[IO^] = leaked[Boxed[IO^], Boxed[IO^] -> Boxed[IO^]](x => x) // error // error // error | ^^^^^^ - | Found: (x: Boxed[box IO^]^?) ->? Boxed[box IO^{x*}]^? - | Required: (x: Boxed[box IO^]) -> Boxed[box IO^²] + | Found: (x: Boxed[IO^]^?) ->? Boxed[IO^{x*}]^? + | Required: Boxed[IO^] -> Boxed[IO^²] | | where: ^ refers to the universal root capability | ^² refers to a fresh root capability created in value x² diff --git a/tests/neg-custom-args/captures/i21442.check b/tests/neg-custom-args/captures/i21442.check index 66bc0727f412..6bf6cf2191ab 100644 --- a/tests/neg-custom-args/captures/i21442.check +++ b/tests/neg-custom-args/captures/i21442.check @@ -6,5 +6,5 @@ -- Error: tests/neg-custom-args/captures/i21442.scala:17:10 ------------------------------------------------------------ 17 | val x1: Boxed[IO^] = x // error | ^^^^^^^^^^ - | Separation failure: value x1's type Boxed[box IO^] hides parameter x. + | Separation failure: value x1's type Boxed[IO^] hides parameter x. | The parameter needs to be annotated with @consume to allow this. diff --git a/tests/neg-custom-args/captures/i21614.check b/tests/neg-custom-args/captures/i21614.check index 5bc01afa4dd0..727817cbb1f5 100644 --- a/tests/neg-custom-args/captures/i21614.check +++ b/tests/neg-custom-args/captures/i21614.check @@ -10,13 +10,13 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i21614.scala:15:12 --------------------------------------- 15 | files.map(new Logger(_)) // error, Q: can we improve the error message? | ^^^^^^^^^^^^^ - |Found: (_$1: box File^{files*}) ->{files*} box Logger{val f: File^{_$1}}^{cap.rd, _$1} - |Required: (_$1: box File^{files*}) => box Logger{val f: File^?}^? + |Found: (_$1: File^{files*}) ->{files*} Logger{val f: File^{_$1}}^{cap.rd, _$1} + |Required: File^{files*} => Logger{val f: File^?}^? | |where: => refers to a fresh root capability created in method mkLoggers2 when checking argument to parameter f of method map - | cap is a root capability associated with the result type of (_$1: box File^{files*}): box Logger{val f: File^{_$1}}^{cap.rd, _$1} + | cap is a root capability associated with the result type of (_$1: File^{files*}): Logger{val f: File^{_$1}}^{cap.rd, _$1} | - |Note that reference .rd + |Note that reference .rd |cannot be included in outer capture set ? | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/i21920.check b/tests/neg-custom-args/captures/i21920.check index 70327a9e413f..9b3de5548f5b 100644 --- a/tests/neg-custom-args/captures/i21920.check +++ b/tests/neg-custom-args/captures/i21920.check @@ -1,13 +1,13 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i21920.scala:34:35 --------------------------------------- 34 | val cell: Cell[File] = File.open(f => Cell(() => Seq(f))) // error | ^^^^^^^^^^^^^^^^^^^^^^^ - |Found: (f: File^?) ->? box Cell[box File^?]{val head: () ->? IterableOnce[box File^?]^?}^? - |Required: (f: File^) => box Cell[box File^?]{val head: () ->? IterableOnce[box File^?]^?}^? + |Found: (f: File^?) ->? Cell[File^?]{val head: () ->? IterableOnce[File^?]^?}^? + |Required: File^ => Cell[File^?]{val head: () ->? IterableOnce[File^?]^?}^? | |where: => refers to a fresh root capability created in value cell when checking argument to parameter f of method open | ^ refers to the universal root capability | - |Note that reference + |Note that reference |cannot be included in outer capture set ? | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/lazylists2.check b/tests/neg-custom-args/captures/lazylists2.check index d1883cc54718..720434cb2a2d 100644 --- a/tests/neg-custom-args/captures/lazylists2.check +++ b/tests/neg-custom-args/captures/lazylists2.check @@ -1,7 +1,7 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazylists2.scala:18:4 ------------------------------------ 18 | final class Mapped extends LazyList[B]: // error | ^ - | Found: LazyList[box B^?]^{f, xs} + | Found: LazyList[B^?]^{f, xs} | Required: LazyList[B]^{f} 19 | this: (Mapped^{xs, f}) => 20 | def isEmpty = false @@ -13,7 +13,7 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazylists2.scala:27:4 ------------------------------------ 27 | final class Mapped extends LazyList[B]: // error | ^ - | Found: LazyList[box B^?]^{f, xs} + | Found: LazyList[B^?]^{f, xs} | Required: LazyList[B]^{xs} 28 | this: Mapped^{xs, f} => 29 | def isEmpty = false @@ -33,7 +33,7 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazylists2.scala:45:4 ------------------------------------ 45 | final class Mapped extends LazyList[B]: // error | ^ - | Found: LazyList[box B^?]^{f, xs} + | Found: LazyList[B^?]^{f, xs} | Required: LazyList[B]^{xs} 46 | this: (Mapped^{xs, f}) => 47 | def isEmpty = false diff --git a/tests/neg-custom-args/captures/leak-problem-2.check b/tests/neg-custom-args/captures/leak-problem-2.check index 42282ff7f9f4..80add5eddd22 100644 --- a/tests/neg-custom-args/captures/leak-problem-2.check +++ b/tests/neg-custom-args/captures/leak-problem-2.check @@ -1,7 +1,7 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/leak-problem-2.scala:8:8 --------------------------------- 8 | = race(Seq(src1, src2)) // error | ^^^^^^^^^^^^^^^^^^^^^ - | Found: Source[box T^?]^{src1, src2} + | Found: Source[T^?]^{src1, src2} | Required: Source[T] | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/leaking-iterators.check b/tests/neg-custom-args/captures/leaking-iterators.check index a64934c41360..9b76d1195309 100644 --- a/tests/neg-custom-args/captures/leaking-iterators.check +++ b/tests/neg-custom-args/captures/leaking-iterators.check @@ -1,8 +1,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/leaking-iterators.scala:56:16 ---------------------------- 56 | usingLogFile: log => // error | ^ - |Found: (log: java.io.FileOutputStream^) ->? box cctest.Iterator[Int]^{log} - |Required: (log: java.io.FileOutputStream^) => box cctest.Iterator[Int]^? + |Found: (log: java.io.FileOutputStream^) ->? cctest.Iterator[Int]^{log} + |Required: java.io.FileOutputStream^ => cctest.Iterator[Int]^? | |where: => refers to a fresh root capability created in method test when checking argument to parameter op of method usingLogFile | ^ refers to the universal root capability diff --git a/tests/neg-custom-args/captures/levels.check b/tests/neg-custom-args/captures/levels.check index dd195c9085aa..dc8994907634 100644 --- a/tests/neg-custom-args/captures/levels.check +++ b/tests/neg-custom-args/captures/levels.check @@ -1,7 +1,7 @@ -- Error: tests/neg-custom-args/captures/levels.scala:17:21 ------------------------------------------------------------ 17 | val _ = Ref[String => String]((x: String) => x) // error | ^^^^^^^^^^^^^^^^ - | Type variable T of constructor Ref cannot be instantiated to box String => String since + | Type variable T of constructor Ref cannot be instantiated to String => String since | that type captures the root capability `cap`. | | where: => refers to the universal root capability @@ -9,6 +9,6 @@ 22 | r.setV(g) // error | ^ | Found: (x: String) ->{cap3} String - | Required: (x: String) -> String + | Required: String -> String | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/nonsensical-for-pure.check b/tests/neg-custom-args/captures/nonsensical-for-pure.check new file mode 100644 index 000000000000..6860446c4177 --- /dev/null +++ b/tests/neg-custom-args/captures/nonsensical-for-pure.check @@ -0,0 +1,4 @@ +-- Error: tests/neg-custom-args/captures/nonsensical-for-pure.scala:1:7 ------------------------------------------------ +1 |val x: Int^ = 2 // error + | ^^^^ + | Int is a pure type, it makes no sense to add a capture set to it diff --git a/tests/neg-custom-args/captures/nonsensical-for-pure.scala b/tests/neg-custom-args/captures/nonsensical-for-pure.scala new file mode 100644 index 000000000000..ffdd9c28e7bf --- /dev/null +++ b/tests/neg-custom-args/captures/nonsensical-for-pure.scala @@ -0,0 +1 @@ +val x: Int^ = 2 // error diff --git a/tests/neg-custom-args/captures/outer-var.check b/tests/neg-custom-args/captures/outer-var.check index fc6662fd7795..d6d9067d9d2f 100644 --- a/tests/neg-custom-args/captures/outer-var.check +++ b/tests/neg-custom-args/captures/outer-var.check @@ -39,7 +39,7 @@ -- Error: tests/neg-custom-args/captures/outer-var.scala:17:57 --------------------------------------------------------- 17 | var finalizeActions = collection.mutable.ListBuffer[() => Unit]() // error, was OK under unsealed | ^^^^^^^^^^ - | Type variable A of object ListBuffer cannot be instantiated to box () => Unit since - | that type captures the root capability `cap`. + | Type variable A of object ListBuffer cannot be instantiated to () => Unit since + | that type captures the root capability `cap`. | - | where: => refers to the universal root capability + | where: => refers to the universal root capability diff --git a/tests/neg-custom-args/captures/reaches.check b/tests/neg-custom-args/captures/reaches.check index 9fc40ff0ee1a..0d683cbaf1ca 100644 --- a/tests/neg-custom-args/captures/reaches.check +++ b/tests/neg-custom-args/captures/reaches.check @@ -2,7 +2,7 @@ 22 | usingFile: f => // error | ^ |Found: (f: File^?) ->? Unit - |Required: (f: File^) => Unit + |Required: File^ => Unit | |where: => refers to a fresh root capability created in method runAll0 when checking argument to parameter f of method usingFile | ^ refers to the universal root capability @@ -13,7 +13,7 @@ 32 | usingFile: f => // error | ^ |Found: (f: File^?) ->? Unit - |Required: (f: File^) => Unit + |Required: File^ => Unit | |where: => refers to a fresh root capability created in method runAll1 when checking argument to parameter f of method usingFile | ^ refers to the universal root capability @@ -24,8 +24,8 @@ -- Error: tests/neg-custom-args/captures/reaches.scala:44:16 ----------------------------------------------------------- 44 | val cur = Ref[List[Proc]](xs) // error | ^^^^^^^^^^ - | Type variable T of constructor Ref cannot be instantiated to List[box () => Unit] since - | the part box () => Unit of that type captures the root capability `cap`. + | Type variable T of constructor Ref cannot be instantiated to List[() => Unit] since + | the part () => Unit of that type captures the root capability `cap`. | | where: => refers to the universal root capability -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches.scala:46:35 -------------------------------------- @@ -41,8 +41,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches.scala:48:20 -------------------------------------- 48 | cur.set(cur.get.tail: List[Proc]) // error | ^^^^^^^^^^^^ - | Found: List[box () => Unit] - | Required: List[box () =>² Unit] + | Found: List[() => Unit] + | Required: List[() =>² Unit] | | where: => refers to the universal root capability | =>² refers to a fresh root capability created in method runAll3 @@ -51,15 +51,15 @@ -- Error: tests/neg-custom-args/captures/reaches.scala:54:51 ----------------------------------------------------------- 54 | val id: Id[Proc, Proc] = new Id[Proc, () -> Unit] // error | ^ - | Type variable A of constructor Id cannot be instantiated to box () => Unit since - | that type captures the root capability `cap`. + | Type variable A of constructor Id cannot be instantiated to () => Unit since + | that type captures the root capability `cap`. | - | where: => refers to the universal root capability + | where: => refers to the universal root capability -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches.scala:59:27 -------------------------------------- 59 | val id: File^ -> File^ = x => x // error | ^^^^^^ | Found: (x: File^) ->? File^{x} - | Required: (x: File^) -> File^² + | Required: File^ -> File^² | | where: ^ refers to the universal root capability | ^² refers to a fresh root capability in the type of value id @@ -81,8 +81,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches.scala:70:38 -------------------------------------- 70 | val leaked = usingFile[File^{id*}]: f => // error | ^ - |Found: (f: File^?) ->? box File^{id*} - |Required: (f: File^) => box File^{id*} + |Found: (f: File^?) ->? File^{id*} + |Required: File^ => File^{id*} | |where: => refers to a fresh root capability created in value leaked when checking argument to parameter f of method usingFile | ^ refers to the universal root capability @@ -98,8 +98,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/reaches.scala:91:10 -------------------------------------- 91 | ps.map((x, y) => compose1(x, y)) // error | ^^^^^^^^^^^^^^^^^^^^^^^ - |Found: (x$1: (box A^ ->? A^?, box A^ ->? A^?)^?) ->? box A^? ->? A^? - |Required: (x$1: (box A ->{ps*} A, box A ->{ps*} A)) => box A^? ->? A^? + |Found: (x$1: (A^ ->? A^?, A^ ->? A^?)^?) ->? A^? ->? A^? + |Required: ((A ->{ps*} A, A ->{ps*} A)) => A^? ->? A^? | |where: => refers to a fresh root capability created in method mapCompose2 when checking argument to parameter f of method map | ^ refers to the universal root capability diff --git a/tests/neg-custom-args/captures/reaches2.check b/tests/neg-custom-args/captures/reaches2.check index e6009b95d581..8391836d611e 100644 --- a/tests/neg-custom-args/captures/reaches2.check +++ b/tests/neg-custom-args/captures/reaches2.check @@ -13,7 +13,7 @@ | ^ |Separation failure: argument of type A ->{x} A |to method compose1: [A, B, C](f: A => B, g: B => C): A ->{f, g} C - |corresponds to capture-polymorphic formal parameter f of type box A^? => box A^? + |corresponds to capture-polymorphic formal parameter f of type A^? => A^? |and hides capabilities {x}. |Some of these overlap with the captures of the second argument with type A ->{y} A. | @@ -23,4 +23,4 @@ | Footprint set of second argument : {y, ps*} | The two sets overlap at : {ps*} | - |where: => refers to a fresh root capability created in anonymous function of type (x$1: (box A^? ->{ps*} A^?, box A^? ->{ps*} A^?)^?): A^? ->{ps*} A^? when checking argument to parameter f of method compose1 + |where: => refers to a fresh root capability created in anonymous function of type (x$1: (A^? ->{ps*} A^?, A^? ->{ps*} A^?)^?): A^? ->{ps*} A^? when checking argument to parameter f of method compose1 diff --git a/tests/neg-custom-args/captures/real-try.check b/tests/neg-custom-args/captures/real-try.check index 4dd51e13f270..c62a775ca70a 100644 --- a/tests/neg-custom-args/captures/real-try.check +++ b/tests/neg-custom-args/captures/real-try.check @@ -43,8 +43,8 @@ -- Error: tests/neg-custom-args/captures/real-try.scala:32:10 ---------------------------------------------------------- 32 | val b = try // error | ^ - | The result of `try` cannot have type Cell[box () ->{cap.rd} Unit]^? since - | the part box () ->{cap.rd} Unit of that type captures the root capability `cap`. + | The result of `try` cannot have type Cell[() ->{cap.rd} Unit]^? since + | the part () ->{cap.rd} Unit of that type captures the root capability `cap`. | This is often caused by a locally generated exception capability leaking as part of its result. | | where: cap is a fresh root capability in the type of given instance canThrow$4 diff --git a/tests/neg-custom-args/captures/scoped-caps.check b/tests/neg-custom-args/captures/scoped-caps.check index b1cf59b2a96d..b92464f8ce6f 100644 --- a/tests/neg-custom-args/captures/scoped-caps.check +++ b/tests/neg-custom-args/captures/scoped-caps.check @@ -87,7 +87,7 @@ 27 | val _: S -> B^ = x => j(x) // error | ^^^^^^^^^ | Found: (x: S^{cap.rd}) ->? B^{x} - | Required: (x: S^{cap.rd}) -> B^ + | Required: S^{cap.rd} -> B^ | | where: ^ refers to a fresh root capability in the type of value _$14 | cap is the universal root capability diff --git a/tests/neg-custom-args/captures/sep-counter.check b/tests/neg-custom-args/captures/sep-counter.check index 112f23b6ecd3..9abfc22b58d0 100644 --- a/tests/neg-custom-args/captures/sep-counter.check +++ b/tests/neg-custom-args/captures/sep-counter.check @@ -1,9 +1,9 @@ -- Error: tests/neg-custom-args/captures/sep-counter.scala:12:19 ------------------------------------------------------- 12 | def mkCounter(): Pair[Ref^, Ref^] = // error | ^^^^^^^^^^^^^^^^ - | Separation failure in method mkCounter's result type Pair[box Ref^, box Ref^²]. - | One part, box Ref^, hides capabilities {cap}. - | Another part, box Ref^², captures capabilities {cap}. + | Separation failure in method mkCounter's result type Pair[Ref^, Ref^²]. + | One part, Ref^, hides capabilities {cap}. + | Another part, Ref^², captures capabilities {cap}. | The two sets overlap at cap of method mkCounter. | | where: ^ refers to a fresh root capability in the result type of method mkCounter diff --git a/tests/neg-custom-args/captures/sep-pairs.check b/tests/neg-custom-args/captures/sep-pairs.check index 07460db49656..4e0492b89777 100644 --- a/tests/neg-custom-args/captures/sep-pairs.check +++ b/tests/neg-custom-args/captures/sep-pairs.check @@ -1,9 +1,9 @@ -- Error: tests/neg-custom-args/captures/sep-pairs.scala:15:10 --------------------------------------------------------- 15 | val r1: Pair[Ref^, Ref^] = mkPair(r0) // error: overlap at r0 | ^^^^^^^^^^^^^^^^ - | Separation failure in value r1's type Pair[box Ref^, box Ref^²]. - | One part, box Ref^, hides capabilities {r0}. - | Another part, box Ref^², captures capabilities {r0}. + | Separation failure in value r1's type Pair[Ref^, Ref^²]. + | One part, Ref^, hides capabilities {r0}. + | Another part, Ref^², captures capabilities {r0}. | The two sets overlap at {r0}. | | where: ^ refers to a fresh root capability in the type of value r1 @@ -11,9 +11,9 @@ -- Error: tests/neg-custom-args/captures/sep-pairs.scala:13:9 ---------------------------------------------------------- 13 |def bad: Pair[Ref^, Ref^] = // error: overlap at r1*, r0 | ^^^^^^^^^^^^^^^^ - | Separation failure in method bad's result type Pair[box Ref^, box Ref^²]. - | One part, box Ref^, hides capabilities {cap, cap², r1*, r0}. - | Another part, box Ref^², captures capabilities {cap, cap², r1*, r0}. + | Separation failure in method bad's result type Pair[Ref^, Ref^²]. + | One part, Ref^, hides capabilities {cap, cap², r1*, r0}. + | Another part, Ref^², captures capabilities {cap, cap², r1*, r0}. | The two sets overlap at {r1*, r0}. | | where: ^ refers to a fresh root capability in the result type of method bad @@ -23,9 +23,9 @@ -- Error: tests/neg-custom-args/captures/sep-pairs.scala:43:18 --------------------------------------------------------- 43 | val sameToPair: Pair[Ref^, Ref^] = Pair(fstSame, sndSame) // error | ^^^^^^^^^^^^^^^^ - | Separation failure in value sameToPair's type Pair[box Ref^, box Ref^²]. - | One part, box Ref^, hides capabilities {fstSame}. - | Another part, box Ref^², captures capabilities {sndSame}. + | Separation failure in value sameToPair's type Pair[Ref^, Ref^²]. + | One part, Ref^, hides capabilities {fstSame}. + | Another part, Ref^², captures capabilities {sndSame}. | The two sets overlap at cap of value same. | | where: ^ refers to a fresh root capability in the type of value sameToPair diff --git a/tests/neg-custom-args/captures/sepchecks2.check b/tests/neg-custom-args/captures/sepchecks2.check index bb1c2bcaa0bd..e7b8dcbf038f 100644 --- a/tests/neg-custom-args/captures/sepchecks2.check +++ b/tests/neg-custom-args/captures/sepchecks2.check @@ -2,16 +2,16 @@ 10 | println(c) // error | ^ | Separation failure: Illegal access to {c} which is hidden by the previous definition - | of value xs with type List[box () => Unit]. + | of value xs with type List[() => Unit]. | This type hides capabilities {c} | | where: => refers to a fresh root capability in the type of value xs -- Error: tests/neg-custom-args/captures/sepchecks2.scala:13:7 --------------------------------------------------------- 13 | foo((() => println(c)) :: Nil, c) // error | ^^^^^^^^^^^^^^^^^^^^^^^^ - |Separation failure: argument of type List[box () ->{c} Unit] - |to method foo: (xs: List[box () => Unit], y: Object^): Nothing - |corresponds to capture-polymorphic formal parameter xs of type List[box () => Unit] + |Separation failure: argument of type List[() ->{c} Unit] + |to method foo: (xs: List[() => Unit], y: Object^): Nothing + |corresponds to capture-polymorphic formal parameter xs of type List[() => Unit] |and hides capabilities {c}. |Some of these overlap with the captures of the second argument with type (c : Object^). | @@ -25,9 +25,9 @@ -- Error: tests/neg-custom-args/captures/sepchecks2.scala:14:10 -------------------------------------------------------- 14 | val x1: (Object^, Object^) = (c, c) // error | ^^^^^^^^^^^^^^^^^^ - | Separation failure in value x1's type (box Object^, box Object^²). - | One part, box Object^, hides capabilities {c}. - | Another part, box Object^², captures capabilities {c}. + | Separation failure in value x1's type (Object^, Object^²). + | One part, Object^, hides capabilities {c}. + | Another part, Object^², captures capabilities {c}. | The two sets overlap at {c}. | | where: ^ refers to a fresh root capability in the type of value x1 @@ -35,18 +35,18 @@ -- Error: tests/neg-custom-args/captures/sepchecks2.scala:15:10 -------------------------------------------------------- 15 | val x2: (Object^, Object^{d}) = (d, d) // error | ^^^^^^^^^^^^^^^^^^^^^ - | Separation failure in value x2's type (box Object^, box Object^{d}). - | One part, box Object^, hides capabilities {d}. - | Another part, box Object^{d}, captures capabilities {d}. + | Separation failure in value x2's type (Object^, Object^{d}). + | One part, Object^, hides capabilities {d}. + | Another part, Object^{d}, captures capabilities {d}. | The two sets overlap at {d}. | | where: ^ refers to a fresh root capability in the type of value x2 -- Error: tests/neg-custom-args/captures/sepchecks2.scala:27:6 --------------------------------------------------------- 27 | bar((c, c)) // error | ^^^^^^ - |Separation failure in the argument's adapted type (box Object^, box Object^²). - |One part, box Object^, hides capabilities {c}. - |Another part, box Object^², captures capabilities {c}. + |Separation failure in the argument's adapted type (Object^, Object^²). + |One part, Object^, hides capabilities {c}. + |Another part, Object^², captures capabilities {c}. |The two sets overlap at {c}. | |where: ^ refers to a fresh root capability created in method Test6 when checking argument to parameter x of method bar @@ -54,10 +54,10 @@ -- Error: tests/neg-custom-args/captures/sepchecks2.scala:30:9 --------------------------------------------------------- 30 | val x: (Object^, Object^{c}) = (d, c) // error | ^^^^^^^^^^^^^^^^^^^^^ - | Separation failure: value x's type (box Object^, box Object^{c}) hides parameter d. + | Separation failure: value x's type (Object^, Object^{c}) hides parameter d. | The parameter needs to be annotated with @consume to allow this. -- Error: tests/neg-custom-args/captures/sepchecks2.scala:33:9 --------------------------------------------------------- 33 | val x: (Object^, Object^) = (c, d) // error | ^^^^^^^^^^^^^^^^^^ - | Separation failure: value x's type (box Object^, box Object^) hides parameters c and d. + | Separation failure: value x's type (Object^, Object^) hides parameters c and d. | The parameters need to be annotated with @consume to allow this. diff --git a/tests/neg-custom-args/captures/simple-using.check b/tests/neg-custom-args/captures/simple-using.check index 3f31f6e41dd2..0ffda05e1547 100644 --- a/tests/neg-custom-args/captures/simple-using.check +++ b/tests/neg-custom-args/captures/simple-using.check @@ -1,8 +1,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/simple-using.scala:8:15 ---------------------------------- 8 | usingLogFile { f => () => f.write(2) } // error | ^^^^^^^^^^^^^^^^^^^^^^^^^ - |Found: (f: java.io.FileOutputStream^) ->? box () ->{f} Unit - |Required: (f: java.io.FileOutputStream^) => box () ->? Unit + |Found: (f: java.io.FileOutputStream^) ->? () ->{f} Unit + |Required: java.io.FileOutputStream^ => () ->? Unit | |where: => refers to a fresh root capability created in method test when checking argument to parameter op of method usingLogFile | ^ refers to the universal root capability diff --git a/tests/neg-custom-args/captures/spread-problem.check b/tests/neg-custom-args/captures/spread-problem.check index 31cf38a51727..91022f920486 100644 --- a/tests/neg-custom-args/captures/spread-problem.check +++ b/tests/neg-custom-args/captures/spread-problem.check @@ -1,14 +1,14 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/spread-problem.scala:8:6 --------------------------------- 8 | race(Seq(src1, src2)*) // error | ^^^^^^^^^^^^^^^^^^^^^^ - | Found: Source[box T^?]^{src1, src2} + | Found: Source[T^?]^{src1, src2} | Required: Source[T] | | longer explanation available when compiling with `-explain` -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/spread-problem.scala:11:6 -------------------------------- 11 | race(src1, src2) // error | ^^^^^^^^^^^^^^^^ - | Found: Source[box T^?]^{src1, src2} + | Found: Source[T^?]^{src1, src2} | Required: Source[T] | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/try.check b/tests/neg-custom-args/captures/try.check index 7d1f2bc7f31d..c470ee13e9ca 100644 --- a/tests/neg-custom-args/captures/try.check +++ b/tests/neg-custom-args/captures/try.check @@ -1,15 +1,15 @@ -- Error: tests/neg-custom-args/captures/try.scala:23:28 --------------------------------------------------------------- 23 | val a = handle[Exception, CanThrow[Exception]] { // error // error | ^^^^^^^^^^^^^^^^^^^ - | Type variable R of method handle cannot be instantiated to box CT[Exception]^ since + | Type variable R of method handle cannot be instantiated to CT[Exception]^ since | that type captures the root capability `cap`. | | where: ^ refers to the universal root capability -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/try.scala:23:49 ------------------------------------------ 23 | val a = handle[Exception, CanThrow[Exception]] { // error // error | ^ - |Found: (x: CT[Exception]^) ->? box CT[Exception]^{x} - |Required: (x: CT[Exception]^) => box CT[Exception]^² + |Found: (x: CT[Exception]^) ->? CT[Exception]^{x} + |Required: CT[Exception]^ => CT[Exception]^² | |where: => refers to a fresh root capability created in value a when checking argument to parameter op of method handle | ^ refers to the universal root capability @@ -22,7 +22,7 @@ 29 | val b = handle[Exception, () -> Nothing] { // error | ^ |Found: (x: CT[Exception]^) ->? () ->{x} Nothing - |Required: (x: CT[Exception]^) => () -> Nothing + |Required: CT[Exception]^ => () -> Nothing | |where: => refers to a fresh root capability created in value b when checking argument to parameter op of method handle | ^ refers to the universal root capability @@ -33,8 +33,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/try.scala:35:18 ------------------------------------------ 35 | val xx = handle { // error | ^ - |Found: (x: CT[Exception]^) ->? box () ->{x} Int - |Required: (x: CT[Exception]^) => box () ->? Int + |Found: (x: CT[Exception]^) ->? () ->{x} Int + |Required: CT[Exception]^ => () ->? Int | |where: => refers to a fresh root capability created in value xx when checking argument to parameter op of method handle | ^ refers to the universal root capability @@ -51,8 +51,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/try.scala:47:31 ------------------------------------------ 47 |val global: () -> Int = handle { // error | ^ - |Found: (x: CT[Exception]^) ->? box () ->{x} Int - |Required: (x: CT[Exception]^) => box () ->? Int + |Found: (x: CT[Exception]^) ->? () ->{x} Int + |Required: CT[Exception]^ => () ->? Int | |where: => refers to a fresh root capability created in value global when checking argument to parameter op of method handle | ^ refers to the universal root capability diff --git a/tests/neg-custom-args/captures/unsound-reach-4.check b/tests/neg-custom-args/captures/unsound-reach-4.check index 361b1158305d..576e3c46186b 100644 --- a/tests/neg-custom-args/captures/unsound-reach-4.check +++ b/tests/neg-custom-args/captures/unsound-reach-4.check @@ -9,7 +9,7 @@ 20 | val backdoor: Foo[File^] = new Bar // error (follow-on, since the parent Foo[File^] of bar is illegal). | ^^^^^^^ | Found: Bar^? - | Required: Foo[box File^] + | Required: Foo[File^] | | where: ^ refers to a fresh root capability in the type of value backdoor | @@ -17,7 +17,7 @@ -- [E164] Declaration Error: tests/neg-custom-args/captures/unsound-reach-4.scala:17:6 --------------------------------- 17 | def use(@consume x: F): File^ = x // error @consume override | ^ - | error overriding method use in trait Foo of type (x: File^): box File^; + | error overriding method use in trait Foo of type (x: File^): File^; | method use of type (@consume x: File^): File^² has incompatible type | | where: ^ refers to the universal root capability diff --git a/tests/neg-custom-args/captures/unsound-reach-6.check b/tests/neg-custom-args/captures/unsound-reach-6.check index 2afe9ba0e1dd..a6a6c69f93bc 100644 --- a/tests/neg-custom-args/captures/unsound-reach-6.check +++ b/tests/neg-custom-args/captures/unsound-reach-6.check @@ -25,4 +25,4 @@ -- Error: tests/neg-custom-args/captures/unsound-reach-6.scala:19:14 --------------------------------------------------- 19 | val z = f(ys) // error @consume failure | ^^ - |Separation failure: argument to @consume parameter with type List[box () ->{io} Unit] refers to non-local parameter io + |Separation failure: argument to @consume parameter with type List[() ->{io} Unit] refers to non-local parameter io diff --git a/tests/neg-custom-args/captures/unsound-reach.check b/tests/neg-custom-args/captures/unsound-reach.check index f8ddb725598d..23af7d907362 100644 --- a/tests/neg-custom-args/captures/unsound-reach.check +++ b/tests/neg-custom-args/captures/unsound-reach.check @@ -8,7 +8,7 @@ -- Error: tests/neg-custom-args/captures/unsound-reach.scala:14:19 ----------------------------------------------------- 14 |class Bar2 extends Foo2[File^]: // error | ^ - | Type variable X of constructor Foo2 cannot be instantiated to box File^ since + | Type variable X of constructor Foo2 cannot be instantiated to File^ since | that type captures the root capability `cap`. | | where: ^ refers to the universal root capability @@ -16,7 +16,7 @@ 18 | val backdoor: Foo[File^] = new Bar // error (follow-on, since the parent Foo[File^] of bar is illegal). | ^^^^^^^ | Found: Bar^? - | Required: Foo[box File^] + | Required: Foo[File^] | | where: ^ refers to a fresh root capability in the type of value backdoor | diff --git a/tests/neg-custom-args/captures/use-capset.check b/tests/neg-custom-args/captures/use-capset.check index d10cf2ccaeb7..082ad2860425 100644 --- a/tests/neg-custom-args/captures/use-capset.check +++ b/tests/neg-custom-args/captures/use-capset.check @@ -13,7 +13,7 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/use-capset.scala:13:50 ----------------------------------- 13 | val _: () -> List[Object^{io}] -> Object^{io} = h2 // error, should be ->{io} | ^^ - | Found: (h2 : () ->{} List[box Object^{io}]^{} ->{io} Object^{io}) - | Required: () -> List[box Object^{io}] -> Object^{io} + | Found: (h2 : () ->{} List[Object^{io}]^{} ->{io} Object^{io}) + | Required: () -> List[Object^{io}] -> Object^{io} | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/usingLogFile.check b/tests/neg-custom-args/captures/usingLogFile.check index 04df1e7aeca6..8b89d58aa446 100644 --- a/tests/neg-custom-args/captures/usingLogFile.check +++ b/tests/neg-custom-args/captures/usingLogFile.check @@ -1,8 +1,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/usingLogFile.scala:22:27 --------------------------------- 22 | val later = usingLogFile { f => () => f.write(0) } // error | ^^^^^^^^^^^^^^^^^^^^^^^^^ - |Found: (f: java.io.FileOutputStream^) ->? box () ->{f} Unit - |Required: (f: java.io.FileOutputStream^) => box () ->? Unit + |Found: (f: java.io.FileOutputStream^) ->? () ->{f} Unit + |Required: java.io.FileOutputStream^ => () ->? Unit | |where: => refers to a fresh root capability created in value later when checking argument to parameter op of method usingLogFile | ^ refers to the universal root capability @@ -14,8 +14,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/usingLogFile.scala:27:36 --------------------------------- 27 | private val later2 = usingLogFile { f => Cell(() => f.write(0)) } // error | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - |Found: (f: java.io.FileOutputStream^) ->? box Test2.Cell[box () ->{f} Unit]^? - |Required: (f: java.io.FileOutputStream^) => box Test2.Cell[box () ->? Unit]^? + |Found: (f: java.io.FileOutputStream^) ->? Test2.Cell[() ->{f} Unit]^? + |Required: java.io.FileOutputStream^ => Test2.Cell[() ->? Unit]^? | |where: => refers to a fresh root capability created in value later2 when checking argument to parameter op of method usingLogFile | ^ refers to the universal root capability @@ -27,8 +27,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/usingLogFile.scala:43:33 --------------------------------- 43 | val later = usingFile("out", f => (y: Int) => xs.foreach(x => f.write(x + y))) // error | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - |Found: (f: java.io.OutputStream^) ->? box Int ->{f} Unit - |Required: (f: java.io.OutputStream^) => box Int ->? Unit + |Found: (f: java.io.OutputStream^) ->? Int ->{f} Unit + |Required: java.io.OutputStream^ => Int ->? Unit | |where: => refers to a fresh root capability created in value later when checking argument to parameter op of method usingFile | ^ refers to the universal root capability @@ -40,8 +40,8 @@ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/usingLogFile.scala:52:6 ---------------------------------- 52 | usingLogger(_, l => () => l.log("test"))) // error after checking mapping scheme | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - |Found: (_$1: java.io.OutputStream^) ->? box () ->{_$1} Unit - |Required: (_$1: java.io.OutputStream^) => box () ->? Unit + |Found: (_$1: java.io.OutputStream^) ->? () ->{_$1} Unit + |Required: java.io.OutputStream^ => () ->? Unit | |where: => refers to a fresh root capability created in value later when checking argument to parameter op of method usingFile | ^ refers to the universal root capability diff --git a/tests/neg-custom-args/captures/vars-simple.check b/tests/neg-custom-args/captures/vars-simple.check index 5f5c6c365638..7454ba0ecfbd 100644 --- a/tests/neg-custom-args/captures/vars-simple.check +++ b/tests/neg-custom-args/captures/vars-simple.check @@ -11,13 +11,13 @@ 16 | a = g // error | ^ | Found: (x: String) ->{cap3} String - | Required: (x: String) ->{cap1, cap2} String + | Required: String ->{cap1, cap2} String | | longer explanation available when compiling with `-explain` -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars-simple.scala:17:12 ---------------------------------- 17 | b = List(g) // error | ^^^^^^^ - | Found: List[box String ->{cap3} String] - | Required: List[box String ->{cap1, cap2} String] + | Found: List[String ->{cap3} String] + | Required: List[String ->{cap1, cap2} String] | | longer explanation available when compiling with `-explain` diff --git a/tests/neg-custom-args/captures/vars.check b/tests/neg-custom-args/captures/vars.check index b6504e5e0029..484f9270e71f 100644 --- a/tests/neg-custom-args/captures/vars.check +++ b/tests/neg-custom-args/captures/vars.check @@ -2,28 +2,28 @@ 24 | a = x => g(x) // error | ^^^^^^^^^ | Found: (x: String) ->{cap3} String - | Required: (x: String) ->{cap1} String + | Required: String ->{cap1} String | | longer explanation available when compiling with `-explain` -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars.scala:25:8 ------------------------------------------ 25 | a = g // error | ^ | Found: (x: String) ->{cap3} String - | Required: (x: String) ->{cap1} String + | Required: String ->{cap1} String | | longer explanation available when compiling with `-explain` -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars.scala:27:12 ----------------------------------------- 27 | b = List(g) // error | ^^^^^^^ - | Found: List[box String ->{cap3} String] - | Required: List[box String ->{cap1, cap2} String] + | Found: List[String ->{cap3} String] + | Required: List[String ->{cap1, cap2} String] | | longer explanation available when compiling with `-explain` -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars.scala:36:8 ------------------------------------------ 36 | local { cap3 => // error | ^ - | Found: (cap3: CC^) ->? box String ->{cap3} String - | Required: (cap3: CC^) -> box String ->? String + | Found: (cap3: CC^) ->? String ->{cap3} String + | Required: CC^ -> String ->? String | | where: ^ refers to the universal root capability | diff --git a/tests/neg-custom-args/captures/widen-reach.check b/tests/neg-custom-args/captures/widen-reach.check index fea47370cb66..5e83c94880dc 100644 --- a/tests/neg-custom-args/captures/widen-reach.check +++ b/tests/neg-custom-args/captures/widen-reach.check @@ -9,7 +9,7 @@ 9 | val foo: IO^ -> IO^ = x => x // error | ^^^^^^ | Found: (x: IO^) ->? IO^{x} - | Required: (x: IO^) -> IO^² + | Required: IO^ -> IO^² | | where: ^ refers to the universal root capability | ^² refers to a fresh root capability in the type of value foo diff --git a/tests/pending/pos-custom-args/captures/list-encoding.scala b/tests/pending/pos-custom-args/captures/list-encoding.scala new file mode 100644 index 000000000000..38e3affa8671 --- /dev/null +++ b/tests/pending/pos-custom-args/captures/list-encoding.scala @@ -0,0 +1,30 @@ +package listEncoding +import annotation.retains + +class Cap + +type Op[T, C] = + T => C => C + + +class STR // used to be pure class String but then the errors don't show up. + +type List[T] = + [C] -> (op: Op[T, C]) -> (s: C) ->{op} C + +def nil[T]: List[T] = + [C] => (op: Op[T, C]) => (s: C) => s + +def cons[T](hd: T, tl: List[T]): List[T] = + [C] => (op: Op[T, C]) => (s: C) => op(hd)(tl(op)(s)) + +def foo(c: Cap^) = + def f(x: STR @retains[c.type], y: STR @retains[c.type]) = + cons(x, cons(y, nil)) // error, should this work? + def f_explicit(x: STR @retains[c.type], y: STR @retains[c.type]) + : [C] => (op: STR^{x, y} => C => C) -> (s: C) ->{op} C = + cons(x, cons(y, nil)) // error, should this work? + def g(x: STR @retains[c.type], y: Any) = + cons(x, cons(y, nil)) + def h(x: STR, y: Any @retains[c.type]) = + cons(x, cons(y, nil)) diff --git a/tests/pos-custom-args/captures/capt-depfun.scala b/tests/pos-custom-args/captures/capt-depfun.scala index bf4fb7da2cd4..fb6866459aba 100644 --- a/tests/pos-custom-args/captures/capt-depfun.scala +++ b/tests/pos-custom-args/captures/capt-depfun.scala @@ -1,21 +1,24 @@ import annotation.retains +import caps.consume class C type Cap = C @retains[caps.cap.type] -type T = (x: Cap) -> String @retains[x.type] +type T = (x: Cap) -> STR @retains[x.type] type ID[X] = X -val aa: ((x: Cap) -> String @retains[x.type]) = (x: Cap) => "" +class STR(s: String) -def f(y: Cap, z: Cap): String @retains[caps.cap.type] = - val a: ((x: Cap) -> String @retains[x.type]) = (x: Cap) => "" +val aa: ((x: Cap) -> STR @retains[x.type]) = (x: Cap) => STR("") + +def f(@consume y: Cap, z: Cap): STR @retains[caps.cap.type] = + val a: ((x: Cap) -> STR @retains[x.type]) = (x: Cap) => STR("") val b = a(y) - val c: String @retains[y.type] = b + val c: STR @retains[y.type] = b def g(): C @retains[y.type | z.type] = ??? val d = a(g()) - val ac: ((x: Cap) -> ID[String @retains[x.type] -> String @retains[x.type]]) = ??? - val bc: String^{y} -> String^{y} = ac(y) - val dc: String -> String^{y, z} = ac(g()) + val ac: ((x: Cap) -> ID[STR @retains[x.type] -> STR @retains[x.type]]) = ??? + val bc: STR^{y} -> STR^{y} = ac(y) + val dc: STR -> STR^{y, z} = ac(g()) c diff --git a/tests/pos-custom-args/captures/capt-depfun2.scala b/tests/pos-custom-args/captures/capt-depfun2.scala index 50b0fa9d3d99..101ea6bb94e1 100644 --- a/tests/pos-custom-args/captures/capt-depfun2.scala +++ b/tests/pos-custom-args/captures/capt-depfun2.scala @@ -1,9 +1,11 @@ import annotation.retains +import caps.consume class C type Cap = C @retains[caps.cap.type] -def f(y: Cap, z: Cap) = +class STR +def f(@consume y: Cap, @consume z: Cap) = def g(): C @retains[y.type | z.type] = ??? - val ac: ((x: Cap) -> Array[String @retains[x.type]]) = ??? - val dc: Array[? >: String <: String]^{y, z} = ac(g()) // needs to be inferred + val ac: ((x: Cap) -> Array[STR @retains[x.type]]) = ??? + val dc: Array[? >: STR <: STR^]^{y, z} = ac(g()) // needs to be inferred val ec = ac(y) diff --git a/tests/pos-custom-args/captures/capt2.scala b/tests/pos-custom-args/captures/capt2.scala index 3bfb1c70fbe8..7690b892d120 100644 --- a/tests/pos-custom-args/captures/capt2.scala +++ b/tests/pos-custom-args/captures/capt2.scala @@ -3,7 +3,7 @@ class C type Cap = C @retains[caps.cap.type] def test1() = - val y: String^ = "" + val y: C^ = C() def x: Object @retains[y.type] = y def test2() = diff --git a/tests/pos-custom-args/captures/caseclass.scala b/tests/pos-custom-args/captures/caseclass.scala index fe7e02b1b6c2..bae55a82c3bc 100644 --- a/tests/pos-custom-args/captures/caseclass.scala +++ b/tests/pos-custom-args/captures/caseclass.scala @@ -1,12 +1,13 @@ class C extends caps.Capability +class STR(s: String) object test1: - case class Ref(x: String^) + case class Ref(x: STR^) def test(c: C) = - val x1 = Ref("hello") + val x1 = Ref(STR("hello")) val y = x1 match case Ref(z) => z - val yc: String = y + val yc: STR = y object test2: case class Ref(x: () => Unit) diff --git a/tests/pos-custom-args/captures/i16116.scala b/tests/pos-custom-args/captures/i16116.scala index fdc386ac40e1..a103b9a740e2 100644 --- a/tests/pos-custom-args/captures/i16116.scala +++ b/tests/pos-custom-args/captures/i16116.scala @@ -26,12 +26,15 @@ object Test { def apply[A](expr: (CpsTransform[F], C) ?=> A): F[A] = ??? } - def asyncPlus[F[_]](a:Int, b:F[Int])(using cps: CpsTransform[F]): Int^{ cps } = - a + (cps.await(b).asInstanceOf[Int]) + class C(x: Int): + def +(that: C): C = ??? + + def asyncPlus[F[_]](a:C, b:F[C])(using cps: CpsTransform[F]): C^{ cps } = + a + (cps.await(b).asInstanceOf[C]) def testExample1Future(): Unit = val fr = cpsAsync[Future] { - val y = asyncPlus(1,Future successful 2).asInstanceOf[Int] + val y = asyncPlus(C(1),Future successful C(2)).asInstanceOf[Int] y+1 } diff --git a/tests/pos-custom-args/captures/i21868.scala b/tests/pos-custom-args/captures/i21868.scala index 560177c87d73..b0d83efc03ca 100644 --- a/tests/pos-custom-args/captures/i21868.scala +++ b/tests/pos-custom-args/captures/i21868.scala @@ -1,14 +1,16 @@ import language.experimental.captureChecking import caps.* +class U + trait AbstractWrong: type C^ <: CapSet // no longer an error, the lower bound becomes CapSet now - def f(): Unit^{C} + def f(): U^{C} trait Abstract1: type C^ >: CapSet <: CapSet^ - def f(): Unit^{C} + def f(): U^{C} trait Abstract2: type C^ <: {cap} - def f(): Unit^{C} \ No newline at end of file + def f(): U^{C} \ No newline at end of file diff --git a/tests/pos-custom-args/captures/inferred-type-ok.scala b/tests/pos-custom-args/captures/inferred-type-ok.scala new file mode 100644 index 000000000000..49b5f05662fe --- /dev/null +++ b/tests/pos-custom-args/captures/inferred-type-ok.scala @@ -0,0 +1,5 @@ +class C + +def t = + val x: C^ = C() + x diff --git a/tests/pos-custom-args/captures/list-encoding.scala b/tests/pos-custom-args/captures/list-encoding.scala deleted file mode 100644 index d427d1ae3f41..000000000000 --- a/tests/pos-custom-args/captures/list-encoding.scala +++ /dev/null @@ -1,24 +0,0 @@ -package listEncoding -import annotation.retains - -class Cap - -type Op[T, C] = - T => C => C - -type List[T] = - [C] -> (op: Op[T, C]) -> (s: C) ->{op} C - -def nil[T]: List[T] = - [C] => (op: Op[T, C]) => (s: C) => s - -def cons[T](hd: T, tl: List[T]): List[T] = - [C] => (op: Op[T, C]) => (s: C) => op(hd)(tl(op)(s)) - -def foo(c: Cap^) = - def f(x: String @retains[c.type], y: String @retains[c.type]) = - cons(x, cons(y, nil)) - def g(x: String @retains[c.type], y: Any) = - cons(x, cons(y, nil)) - def h(x: String, y: Any @retains[c.type]) = - cons(x, cons(y, nil)) diff --git a/tests/pos-custom-args/captures/trickyTrailingUpArrow.scala b/tests/pos-custom-args/captures/trickyTrailingUpArrow.scala index 71b663de5354..1ca4403a54b7 100644 --- a/tests/pos-custom-args/captures/trickyTrailingUpArrow.scala +++ b/tests/pos-custom-args/captures/trickyTrailingUpArrow.scala @@ -1,9 +1,10 @@ -object Test: + class STR + object Test: var x = 0 - type FreshContext = String^ + type FreshContext = STR^ x += 1 - inline def ctx(using c: String) = c + inline def ctx(using c: STR) = c - val y: String^ -> Unit = ??? - val z: String^ ?-> Unit = ??? + val y: STR^ -> Unit = ??? + val z: STR^ ?-> Unit = ???