File tree Expand file tree Collapse file tree 7 files changed +27
-21
lines changed
compiler/src/dotty/tools/dotc/cc
tests/neg-custom-args/captures Expand file tree Collapse file tree 7 files changed +27
-21
lines changed Original file line number Diff line number Diff line change @@ -693,7 +693,7 @@ object Capabilities:
693
693
thisMap =>
694
694
695
695
override def apply (t : Type ) =
696
- if variance <= 0 then t
696
+ if variance < 0 then t
697
697
else t match
698
698
case t @ CapturingType (_, _) =>
699
699
mapOver(t)
@@ -703,6 +703,8 @@ object Capabilities:
703
703
this (CapturingType (parent1, ann.tree.toCaptureSet))
704
704
else
705
705
t.derivedAnnotatedType(parent1, ann)
706
+ case t @ FunctionOrMethod (_, _) if t.isAliasFun =>
707
+ t // stop at dependent function types
706
708
case _ =>
707
709
mapFollowingAliases(t)
708
710
Original file line number Diff line number Diff line change 3
3
| ^
4
4
| Type argument test.Tree^ does not conform to upper bound test.Tree in inferred type test.C[test.Tree^]
5
5
|
6
- | where: ^ refers to the universal root capability
6
+ | where: ^ refers to a fresh root capability in the type of value foo
7
7
|
8
8
| longer explanation available when compiling with `-explain`
9
9
-- [E057] Type Mismatch Error: tests/neg-custom-args/captures/boundschecks3.scala:10:11 --------------------------------
10
10
10 | type T = C[Tree^] // error
11
11
| ^
12
12
| Type argument test.Tree^ does not conform to upper bound test.Tree in inferred type test.C[test.Tree^]
13
13
|
14
- | where: ^ refers to the universal root capability
14
+ | where: ^ refers to a fresh root capability in the type of type T
15
15
|
16
16
| longer explanation available when compiling with `-explain`
17
17
-- [E057] Type Mismatch Error: tests/neg-custom-args/captures/boundschecks3.scala:11:11 --------------------------------
Original file line number Diff line number Diff line change 1
- -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/box-adapt-cases.scala:8:10 -------------------------------
2
- 8 | x.value(cap => cap.use()) // error, was OK
3
- | ^^^^^^^^^^^^^^^^
4
- | Found: (cap: Cap^?) => Int
5
- | Required: Cap^ =>² Int
6
- |
7
- | where: => refers to the universal root capability
8
- | =>² refers to a fresh root capability created in method test1
9
- | ^ refers to the universal root capability
10
- |
11
- | longer explanation available when compiling with `-explain`
12
1
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/box-adapt-cases.scala:15:10 ------------------------------
13
2
15 | x.value(cap => cap.use()) // error
14
3
| ^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ def test1(): Unit = {
5
5
class Id [X ](val value : [T ] -> (op : X => T ) -> T )
6
6
7
7
val x : Id [Cap ^ ] = ???
8
- x.value(cap => cap.use()) // error, was OK
8
+ x.value(cap => cap.use())
9
9
}
10
10
11
11
def test2 (io : Cap ^ ): Unit = {
Original file line number Diff line number Diff line change
1
+ -- Error: tests/neg-custom-args/captures/class-level-attack.scala:12:24 ------------------------------------------------
2
+ 12 | val r: Ref[IO^] = Ref[IO^](io) // error:
3
+ | ^^^
4
+ | Type variable X of constructor Ref cannot be instantiated to IO^ since
5
+ | that type captures the root capability `cap`.
6
+ |
7
+ | where: ^ refers to the universal root capability
8
+ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/class-level-attack.scala:17:26 ---------------------------
9
+ 17 | def set(x: IO^) = r.put(x) // error
10
+ | ^
11
+ | Found: IO^{x}
12
+ | Required: IO^
13
+ |
14
+ | where: ^ refers to a fresh root capability in the type of value r
15
+ |
16
+ | longer explanation available when compiling with `-explain`
Original file line number Diff line number Diff line change @@ -13,9 +13,8 @@ class C(io: IO^):
13
13
// Type variable X of constructor Ref cannot be instantiated to box IO^ since
14
14
// that type captures the root capability `cap`.
15
15
// where: ^ refers to the universal root capability
16
- val r2 : Ref [IO ^ ] = Ref (io) // error:
17
- // Error: Ref[IO^{io}] does not conform to Ref[IO^] (since Refs are invariant)
18
- def set (x : IO ^ ) = r.put(x)
16
+ val r2 : Ref [IO ^ ] = Ref (io)
17
+ def set (x : IO ^ ) = r.put(x) // error
19
18
20
19
def outer (outerio : IO ^ ) =
21
20
val c = C (outerio)
Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ def usingIO[T](op: IO => T): T = ???
6
6
class Wrapper [T ](val value : [R ] -> (f : T => R ) -> R )
7
7
def mk [T ](x : T ): Wrapper [T ] = Wrapper ([R ] => f => f(x))
8
8
def useWrappedIO (wrapper : Wrapper [IO ]): () -> Unit =
9
- () =>
10
- wrapper.value: io => // error
9
+ () => // error
10
+ wrapper.value: io =>
11
11
io.brewCoffee()
12
12
def main (): Unit =
13
- val escaped = usingIO(io => useWrappedIO(mk(io))) // error
13
+ val escaped = usingIO(io => useWrappedIO(mk(io)))
14
14
escaped() // boom
You can’t perform that action at this time.
0 commit comments