Skip to content

Commit c226577

Browse files
committed
Refactor tests and fix isGlobal
1 parent c03b577 commit c226577

File tree

9 files changed

+23
-1
lines changed

9 files changed

+23
-1
lines changed

compiler/src/dotty/tools/dotc/typer/CheckCaptures.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class CheckCaptures extends RefineTypes:
124124
val isGlobal = ref match
125125
case ref: TypeRef => ref.isRootCapability
126126
case ref: TermRef => ref.prefix != NoPrefix && ref.symbol.hasAnnotation(defn.AbilityAnnot)
127+
case _ => false
127128
val what = if ref.isRootCapability then "universal" else "global"
128129
if isGlobal then
129130
val notAllowed = i" is not allowed to capture the $what capability $ref"

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class CompilationTests {
3333
compileFilesInDir("tests/pos-special/sourcepath/outer", defaultOptions.and("-sourcepath", "tests/pos-special/sourcepath")),
3434
compileFile("tests/pos-special/sourcepath/outer/nested/Test4.scala", defaultOptions.and("-sourcepath", "tests/pos-special/sourcepath")),
3535
compileFilesInDir("tests/pos-special/fatal-warnings", defaultOptions.and("-Xfatal-warnings", "-deprecation", "-feature")),
36-
compileFilesInDir("tests/pos-special/captures", defaultOptions.and("-Ycc")),
3736
compileFile("tests/pos-special/avoid-warn-deprecation.scala", defaultOptions.and("-Xfatal-warnings", "-feature")),
3837
compileFilesInDir("tests/pos-special/spec-t5545", defaultOptions),
3938
compileFilesInDir("tests/pos-special/strawman-collections", allowDeepSubtypes),
4039
compileFilesInDir("tests/pos-special/isInstanceOf", allowDeepSubtypes.and("-Xfatal-warnings")),
4140
compileFilesInDir("tests/new", defaultOptions),
4241
compileFilesInDir("tests/pos-scala2", scala2CompatMode),
42+
compileFilesInDir("tests/pos-custom-args/captures", defaultOptions.and("-Ycc")),
4343
compileFilesInDir("tests/pos-custom-args/erased", defaultOptions.and("-language:experimental.erasedDefinitions")),
4444
compileFilesInDir("tests/pos", defaultOptions.and("-Ysafe-init")),
4545
compileFilesInDir("tests/pos-deep-subtype", allowDeepSubtypes),
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
sealed trait IO:
2+
def puts(msg: Any): Unit = println(msg)
3+
4+
def test1 =
5+
val IO : IO retains * = new IO {}
6+
def foo = IO.puts("hello")
7+
val x : () => Unit = () => foo // error: Found: (() => Unit) retains IO; Required: () => Unit
8+
9+
def test2 =
10+
val IO : IO retains * = new IO {}
11+
def puts(msg: Any, io: IO retains *) = println(msg)
12+
def foo() = puts("hello", IO)
13+
val x : () => Unit = () => foo() // error: Found: (() => Unit) retains IO; Required: () => Unit
14+
15+
type Capability[T] = T retains *
16+
17+
def test3 =
18+
val IO : Capability[IO] = new IO {}
19+
def puts(msg: Any, io: Capability[IO]) = println(msg)
20+
def foo() = puts("hello", IO)
21+
val x : () => Unit = () => foo() // error: Found: (() => Unit) retains IO; Required: () => Unit

0 commit comments

Comments
 (0)