fix: Scala 3.9 context bound and trait field compatibility#3082
Draft
He-Pin wants to merge 3 commits into
Draft
Conversation
Motivation: Scala 3.9.0-RC1 changes context bound desugaring and trait field bytecode generation. ClassTag/LogSource explicit passing via method(args)(ClassTag(x)) breaks, and private val in traits generates abstract setters visible to Java subclasses. Modification: - Behaviors.scala: use implicit val ClassTag instead of explicit passing for monitor, transformMessages, and withMdc methods - Ops.scala: use implicit val LogSource instead of explicit passing for Log and LogWithMarker preStart methods - FSM.scala, PersistentFSMBase.scala: change private val handleEventDefault to private def to avoid abstract setter generation Result: ClassTag and LogSource context bound errors resolved. handleEventDefault setter issue partially mitigated (remaining setters tracked in scala/scala3#26372). Tests: - sbt "++3.9.0-RC1!; compile" resolves ClassTag/LogSource errors References: scala/scala3#26372 - trait setter generic signature regression
He-Pin
commented
Jun 18, 2026
| * unhandled event handler | ||
| */ | ||
| private val handleEventDefault: StateFunction = { | ||
| private def handleEventDefault: StateFunction = { |
Member
There was a problem hiding this comment.
are we going to wait or will we log an issue to revert this when Scala team fix it?
We should link to the Scala bug.
Member
Author
There was a problem hiding this comment.
scala/scala3#26374 @pjfanning maybe we can wait the RC2 ?
Member
Author
There was a problem hiding this comment.
Yes, have to wait, I want to make Pekko project 3.9.0 ready, then we can help capture new bugs
Member
Author
There was a problem hiding this comment.
And I found Pekko's projects do help capture some bugs during the RC release
Motivation: Scala 3.9 removed the -Yfuture-lazy-vals compiler option as the behavior is now the default. Passing this flag causes compilation errors on Scala 3.9+. Modification: Conditionally add -Yfuture-lazy-vals only when Scala minor version < 9 using CrossVersion.partialVersion check. Result: Project compiles on both Scala 3.3.x (which needs the flag) and Scala 3.9+ (which has the behavior by default).
Motivation: CI scalafmt check failed because project/PekkoBuild.scala was not formatted. Modification: Ran scalafmt on the build file. Result: scalafmtSbtCheck and Code is formatted CI checks should pass. Tests: Not run - formatting only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Scala 3.9.0-RC1 introduces breaking changes:
[T: ClassTag]now desugars differently, makingmethod(args)(ClassTag(clazz))fail with "No ClassTag available for T"private valin traits generates abstract setter methods with generic type signatures that mismatch between trait and implementing class, causing Java subclass compilation failuresModification
implicit val ct: ClassTag[T] = ClassTag(clazz)+ implicit resolution instead of explicitClassTag(clazz)passing formonitor,transformMessages, andwithMdcmethodsimplicit val ls: LogSource[Materializer] = fromMaterializer+ implicit resolution instead of explicit passing forLogandLogWithMarkerpreStart methodsprivate val handleEventDefaulttoprivate def handleEventDefaultto avoid abstract setter generation for this specific fieldResult
handleEventDefaultsetter issue is partially mitigated; remaining trait setter issues are tracked in Scala 3.9.0-RC1: trait private val setter generates generic signature that Java subclasses cannot implement scala/scala3#26372 as a Scala 3.9 compiler regressionTests
sbt "++3.9.0-RC1!; compile"— ClassTag/LogSource errors resolvedReferences
private valsetter generates generic signature that Java subclasses cannot implement (Scala 3.9 regression)