Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fcfee4c

Browse files
authored
Set context owner to the method for paramsToCap (#23436)
Fixes #23431.
2 parents 1452ba2 + dcc1931 commit fcfee4c

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

‎compiler/src/dotty/tools/dotc/cc/Setup.scala‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
667667
def newInfo(using Context) = // will be run in this or next phase
668668
toResultInResults(sym, report.error(_, tree.srcPos)):
669669
if sym.is(Method) then
670-
paramsToCap(methodType(paramSymss, localReturnType))
670+
inContext(ctx.withOwner(sym)):
671+
paramsToCap(methodType(paramSymss, localReturnType))
671672
else tree.tpt.nuType
672673
if tree.tpt.isInstanceOf[InferredTypeTree]
673674
&& !sym.is(Param) && !sym.is(ParamAccessor)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i23431.scala:8:13 ----------------------------------------
2+
8 | myIO = io // error, level mismatch
3+
| ^^
4+
| Found: (io : IO^)
5+
| Required: IO^2
6+
|
7+
| where: ^ refers to a fresh root capability in the type of parameter io
8+
| ^2 refers to a fresh root capability in the type of variable myIO
9+
|
10+
| longer explanation available when compiling with `-explain`
11+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i23431.scala:11:13 ---------------------------------------
12+
11 | myIO = io2 // error, level mismatch
13+
| ^^^
14+
| Found: (io2 : IO^)
15+
| Required: IO^2
16+
|
17+
| where: ^ refers to a fresh root capability in the type of parameter io2
18+
| ^2 refers to a fresh root capability in the type of variable myIO
19+
|
20+
| longer explanation available when compiling with `-explain`
21+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i23431.scala:12:12 ---------------------------------------
22+
12 | withIO: io3 => // error
23+
| ^
24+
|Found: (io3: IO^?) ->? Unit
25+
|Required: IO^ => Unit
26+
|
27+
|where: => refers to a fresh root capability created in anonymous function of type (io1: IO^): Unit when checking argument to parameter op of method withIO
28+
| ^ refers to the universal root capability
29+
13 | myIO = io3
30+
|
31+
| longer explanation available when compiling with `-explain`
32+
-- Error: tests/neg-custom-args/captures/i23431.scala:6:14 -------------------------------------------------------------
33+
6 | var myIO: IO^ = io1 // error: separation
34+
| ^^^
35+
| Separation failure: variable myIO's type IO^ hides parameter io1.
36+
| The parameter needs to be annotated with @consume to allow this.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import language.experimental.captureChecking
2+
trait IO
3+
def withIO(op: IO^ => Unit): Unit = ???
4+
def test(): Unit =
5+
withIO: io1 =>
6+
var myIO: IO^ = io1 // error: separation
7+
def setIO(io: IO^): Unit =
8+
myIO = io // error, level mismatch
9+
withIO(setIO)
10+
withIO: (io2: IO^) =>
11+
myIO = io2 // error, level mismatch
12+
withIO: io3 => // error
13+
myIO = io3

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /