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

Fix incorrect self type of closures #2554

Merged

Conversation

WojciechMazur
Copy link
Contributor

@WojciechMazur WojciechMazur commented Feb 7, 2022

This PR fixes #2552 and its reachability errors. The problem with the mentioned issue was caused by usage of incorrect self type for the object containing closure ( SN synthetic Lambda class) and was partially introduced due to changes of how symbols ownership is perceived in Scala 3 or due to the fact that genNir phase is executed after flatten scalac phase.
When generating the closure symbol of the current class saved in curClassSym in the outer scope of AST traversal was different the owner of function passed to the Closure.

object example {
  val foo = () => println("foo") // curClassSym = `example$`; closure.fun.owner = `example$` 
  object inner {
    val foo = () => println("inner foo") // curClassSym = `example$`; closure.fun.owner = `example$foo$`
  }
}

We cannot change the naming of the Scala Native synthetic Lambda class at this point because it might lead to binary incompatibility with 0.4.3 release. Luckily, this is not needed. Reachability errors that we could have observed were caused by method dispatch which was using incorrect self type. Using closure.fun.owner for self type instead of curClassStm fixes the problem.

  • Added reproducer tests for issue 2552
  • Changed self type used for closure inner structure

Additional fix:

  • I've observed warning when compiling scalalib, removing tail whitespace from patches fixed that issue

@WojciechMazur WojciechMazur merged commit 28fbda9 into scala-native:main Feb 8, 2022
@WojciechMazur WojciechMazur deleted the fix/closures-inner-object branch February 8, 2022 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reachability error in scala 3.1.1
1 participant