Repository navigation
Conversation
Motivation: On Scala 3, `Logging(system, getClass)` fails to compile with "Cannot find LogSource for Class[? <: Foo]". `getClass` returns a wildcard class type, which Scala 3 does not match against `LogSource.fromAnyClass[T]: LogSource[Class[T]]`. Scala 2.13 accepts it. Modification: - Make `object LogSource` extend a new `LogSourceCompat` trait. - The Scala 3 `LogSourceCompat` adds a lower priority `fromAnySubClass[T]: LogSource[Class[? <: T]]` implicit; the Scala 2.13 version is empty because Scala 2 reports that implicit as ambiguous with `fromAnyClass`. - `fromAnyClass` is unchanged; changing its signature instead fails MiMa with an IncompatibleSignatureProblem. - Add `LogSourceSpec`. Result: `Logging(system, getClass)` and `LogSource(getClass, system)` compile on Scala 3. Tests: - `actor-tests/Test/testOnly org.apache.pekko.event.LogSourceSpec` on Scala 3.3.8 without the fix: compile error "Cannot find LogSource for Class[? <: ...LogsWithGetClass]" - `actor-tests/Test/testOnly org.apache.pekko.event.LogSourceSpec org.apache.pekko.event.LoggerSpec` with the fix: passed on 2.13.18 and 3.3.8 - `actor/mimaReportBinaryIssues`: passed on 2.13.18 and 3.3.8 - scalafmt run on changed files References: Fixes apache#1538
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
On Scala 3,
Logging(system, getClass)fails to compile withCannot find LogSource for Class[? <: Foo].getClassreturns a wildcard class type, which Scala 3 does not match againstLogSource.fromAnyClass[T]: LogSource[Class[T]]. Scala 2.13 accepts the same code.Modification
object LogSourcenow extends a newLogSourceCompattrait.LogSourceCompatadds a lower priorityfromAnySubClass[T]: LogSource[Class[? <: T]]implicit. The Scala 2.13 version is empty, because Scala 2 reports that implicit as ambiguous withfromAnyClass.fromAnyClassis unchanged. Changing its signature toLogSource[Class[? <: T]]also works, but MiMa reports anIncompatibleSignatureProblem.LogSourceSpec.Result
Logging(system, getClass)andLogSource(getClass, system)compile on Scala 3.Tests
actor-tests/Test/testOnly org.apache.pekko.event.LogSourceSpecon Scala 3.3.8 without the fix: compile errorCannot find LogSource for Class[? <: ...LogsWithGetClass]actor-tests/Test/testOnly org.apache.pekko.event.LogSourceSpec org.apache.pekko.event.LoggerSpecwith the fix: passed on 2.13.18 and 3.3.8actor/mimaReportBinaryIssues: passed on 2.13.18 and 3.3.8References
Fixes #1538