Skip to content
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

Context function is eagerly applied inside a capture set #16944

Open
reftrans opened this issue Feb 17, 2023 · 3 comments
Open

Context function is eagerly applied inside a capture set #16944

reftrans opened this issue Feb 17, 2023 · 3 comments
Labels
area:experimental:cc Capture checking related cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug

Comments

@reftrans
Copy link

Compiler version

Scala 3.2.2 and latest snapshot (250757732398b92cb6fc8f02e50526573f1ba2b9).

Minimized code

import language.experimental.captureChecking
def fn(ap: String ?=> Int)(using str: String): {ap} Int = ap(using str)

Output

Compile error:

4 |def fn(ap: String ?=> Int)(using str: String): {ap} Int = ap(using str)
  |                                                ^^
  |                                                ap.apply(str): Int is not a legal element of a capture set
1 error found

It compiles as expected if ap is a normal (non-context) function.

Expectation

Successful compilation, like with a normal function.

@reftrans reftrans added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 17, 2023
@prolativ prolativ added cc-experiment Intended to be merged with cc-experiment branch on origin and removed itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 17, 2023
@prolativ
Copy link
Contributor

For reference: other issues, where too eager application of context functions caused some problems:
#16540
#16506
#16488
#16035
#15995

@reftrans
Copy link
Author

This problem is actually more simple than I thought. This demonstrates the problem:

import language.experimental.captureChecking
def fn(ap: String ?=> Int): Int^{ap} = ap(using "")

It's not possible to refer to the context function, ap without its parameter getting applied. Even writing it as a @retains annotation and trying to force it stay as an unapplied context function does not work.

@Gedochao
Copy link
Contributor

Note: if I'm not mistaken, the minimized code from the original post has a typo, I believe it should be:

import language.experimental.captureChecking
def fn(ap: String ?=> Int)(using str: String): Int^{ap} = ap(using str)

This produced the initially reported error on the current main:

[info] running (fork) dotty.tools.dotc.Main -classpath /Users/pchabelski/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar:/Users/pchabelski/IdeaProjects/dotty2/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala3-library_3-3.4.0-RC1-bin-SNAPSHOT.jar -d . smth.scala
-- Error: smth.scala:2:52 ------------------------------------------------------
2 |def fn(ap: String ?=> Int)(using str: String): Int^{ap} = ap(using str)
  |                                                    ^^
  |                ap.apply(str): Int is not a legal element of a capture set
1 error found
[error] Nonzero exit code returned from runner: 1

@Gedochao Gedochao added itype:bug area:experimental:cc Capture checking related labels Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental:cc Capture checking related cc-experiment Intended to be merged with cc-experiment branch on origin itype:bug
Projects
None yet
Development

No branches or pull requests

3 participants