Skip to content

Set context owner to the method for paramsToCap #23436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/cc/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,8 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
def newInfo(using Context) = // will be run in this or next phase
toResultInResults(sym, report.error(_, tree.srcPos)):
if sym.is(Method) then
paramsToCap(methodType(paramSymss, localReturnType))
inContext(ctx.withOwner(sym)):
paramsToCap(methodType(paramSymss, localReturnType))
else tree.tpt.nuType
if tree.tpt.isInstanceOf[InferredTypeTree]
&& !sym.is(Param) && !sym.is(ParamAccessor)
Expand Down
36 changes: 36 additions & 0 deletions tests/neg-custom-args/captures/i23431.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i23431.scala:8:13 ----------------------------------------
8 | myIO = io // error, level mismatch
| ^^
| Found: (io : IO^)
| Required: IO^²
|
| where: ^ refers to a fresh root capability in the type of parameter io
| ^² refers to a fresh root capability in the type of variable myIO
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i23431.scala:11:13 ---------------------------------------
11 | myIO = io2 // error, level mismatch
| ^^^
| Found: (io2 : IO^)
| Required: IO^²
|
| where: ^ refers to a fresh root capability in the type of parameter io2
| ^² refers to a fresh root capability in the type of variable myIO
|
| longer explanation available when compiling with `-explain`
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i23431.scala:12:12 ---------------------------------------
12 | withIO: io3 => // error
| ^
|Found: (io3: IO^?) ->? Unit
|Required: IO^ => Unit
|
|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
| ^ refers to the universal root capability
13 | myIO = io3
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg-custom-args/captures/i23431.scala:6:14 -------------------------------------------------------------
6 | var myIO: IO^ = io1 // error: separation
| ^^^
| Separation failure: variable myIO's type IO^ hides parameter io1.
| The parameter needs to be annotated with @consume to allow this.
13 changes: 13 additions & 0 deletions tests/neg-custom-args/captures/i23431.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import language.experimental.captureChecking
trait IO
def withIO(op: IO^ => Unit): Unit = ???
def test(): Unit =
withIO: io1 =>
var myIO: IO^ = io1 // error: separation
def setIO(io: IO^): Unit =
myIO = io // error, level mismatch
withIO(setIO)
withIO: (io2: IO^) =>
myIO = io2 // error, level mismatch
withIO: io3 => // error
myIO = io3
Loading