Skip to content

Cannot create impure partial functions with scala2-library-cc #23225

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

Open
natsukagami opened this issue May 21, 2025 · 0 comments
Open

Cannot create impure partial functions with scala2-library-cc #23225

natsukagami opened this issue May 21, 2025 · 0 comments
Labels
area:experimental:cc Capture checking related area:scala2-library-tasty Any issue generaing or using the Scala 2 library TASTy itype:bug

Comments

@natsukagami
Copy link
Contributor

Compiler version

Latest main

Minimized code

//> using scala 3.7.2-RC1-bin-SNAPSHOT
//> using dep org.scala-lang::scala2-library-cc-tasty-experimental::3.7.2-RC1-bin-SNAPSHOT
import language.experimental.captureChecking
import scala.caps.Capability

class A

def run(f: PartialFunction[A, A]^): A = f(A())

class File extends Capability:
  def read() = ()

def main() =
  val file = File()

  run:
    case a =>
      file.read()
      a

Output

[error] ./partial-function.scala:17:5
[error] illegal inheritance: self type 
[error]   scala.runtime.AbstractPartialFunction[Option[partialfunctions.A],
[error]     partialfunctions.A]
[error]  with Serializable {...}^{file} of anonymous class
[error]   
[error]     scala.runtime.AbstractPartialFunction[Option[partialfunctions.A],
[error]       partialfunctions.A]
[error]    with 
[error] Serializable {...} does not conform to self type scala.runtime.AbstractPartialFunction[Option[partialfunctions.A],
[error]   partialfunctions.A]
[error] of parent class AbstractPartialFunction

This is due to AbstractPartialFunction being declared with a self =>, which assumes a pure self type:

abstract class AbstractPartialFunction[@specialized(Specializable.Arg) -T1, @specialized(Specializable.Return) +R] extends Function1[T1, R] with PartialFunction[T1, R] { self =>
  // ...
}

Since AbstractPartialFunction is specialized, not sure if we can override this in scala2-library-cc Tasty.

Expectation

Should compile.

@natsukagami natsukagami added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:experimental:cc Capture checking related area:scala2-library-tasty Any issue generaing or using the Scala 2 library TASTy labels May 21, 2025
@Gedochao Gedochao removed the stat:needs triage Every issue needs to have an "area" and "itype" label label May 23, 2025
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 area:scala2-library-tasty Any issue generaing or using the Scala 2 library TASTy itype:bug
Projects
None yet
Development

No branches or pull requests

2 participants