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

Pickler crashes when pickling a program compiled with Scala 2 library CC #19990

Closed
Linyxus opened this issue Mar 20, 2024 · 2 comments · Fixed by #20005
Closed

Pickler crashes when pickling a program compiled with Scala 2 library CC #19990

Linyxus opened this issue Mar 20, 2024 · 2 comments · Fixed by #20005
Assignees
Labels
area:experimental:cc Capture checking related itype:bug
Milestone

Comments

@Linyxus
Copy link
Contributor

Linyxus commented Mar 20, 2024

Compiler version

main

Minimized code

First set the library to the capture checked one and then compile the following snippet:

object Test {
  def indentLines(level: Int, lines: Iterable[String]) =
    lines.map(line => line.split("\n").map("  " + _).mkString("\n"))

  def indentErrorMessages(messages: IndexedSeq[String]) =
    indentLines(1, messages)
}

Output

error when pickling type lines.type
error when pickling tree this
error when pickling tree [this,f : Any]
error when pickling tree [this,f : Any]*
error when pickling tree new _root_.scala.annotation.retains([this,f : Any]*)
error when pickling type Iterable[String]^{this, String => String}
error when pickling tree Iterable[String]^{this, String => String}
error when pickling tree def indentErrorMessages(messages: IndexedSeq[String]): Iterable[String]^{this, String => String} = Test.indentLines(1, messages)
...
@Linyxus Linyxus added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:experimental:cc Capture checking related and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 20, 2024
@Linyxus Linyxus self-assigned this Mar 20, 2024
@Linyxus
Copy link
Contributor Author

Linyxus commented Mar 23, 2024

I minimised the issue into the following which is independent of the capture checked library:

import language.experimental.captureChecking

trait Iterable[T] { self: Iterable[T]^ =>
  def map[U](f: T => U): Iterable[U]^{this, f}
}

object Test {
  def indentLines(level: Int, lines: Iterable[String]) =
    lines.map(line => line.split("\n").map("  " + _).mkString("\n"))

  def indentErrorMessages(messages: Iterable[String]) =
    indentLines(1, messages)
}

@Linyxus
Copy link
Contributor Author

Linyxus commented Mar 23, 2024

After typer, the function indentErrorMessages is typed as:

    def indentErrorMessages(messages: Iterable[String]): Iterable[String]^{this, String -> String} = Test.indentLines(1, messages)

The type of this in the capture set of the result type is TermParamRef(lines) (which is the term parameter from the indentLines function). It is invalid and crashes the pickler.

The cause is that when typing the application indentLines(1, messages), the dependency of the result type of the indentLines function is ignored by isResultDependent, which uses the refersToParamOf method to check whether an annotation has possible dependencies on the term parameters. That function, in turn, does not correctly handle the case when it contains a This reference whose type contains references to term parameters.

odersky added a commit that referenced this issue Mar 23, 2024
fixes #19990

See the
[comment](#19990 (comment))
of that issue for an explanation of this issue.
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
@Kordyjan Kordyjan modified the milestones: 3.4.2, 3.5.0 May 10, 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 itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants