pekko icon indicating copy to clipboard operation
pekko copied to clipboard

compiling with latest scala 2.13.17 nightly has compile issues (due to compile warnings)

Open pjfanning opened this issue 4 months ago • 8 comments

Pekko build is set up to fail if we get compile warnings.

Scala nightly 2.13.17-bin-6a23d33

pekko-actor but there could be more in other modules

[error] /Users/pj.fanning/code/pekko/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala:184:15: Calls to parameterless method toArray will be easy to mistake for calls to final override def toArray[B >: Byte](implicit arg0: scala.reflect.ClassTag[B]): Array[B], which has a single implicit parameter list.
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-overload, site=org.apache.pekko.util.ByteString.ByteString1C
[error]   final class ByteString1C private (private val bytes: Array[Byte]) extends CompactByteString {
[error]               ^
[error] /Users/pj.fanning/code/pekko/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala:315:15: Calls to parameterless method toArray will be easy to mistake for calls to final override def toArray[B >: Byte](implicit arg0: scala.reflect.ClassTag[B]): Array[B], which has a single implicit parameter list.
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-overload, site=org.apache.pekko.util.ByteString.ByteString1
[error]   final class ByteString1 private (private val bytes: Array[Byte], private val startIndex: Int, val length: Int)
[error]               ^
[error] /Users/pj.fanning/code/pekko/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala:547:15: Calls to parameterless method toArray will be easy to mistake for calls to final override def toArray[B >: Byte](implicit arg0: scala.reflect.ClassTag[B]): Array[B], which has a single implicit parameter list.
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-overload, site=org.apache.pekko.util.ByteString.ByteStrings
[error]   final class ByteStrings private (private[pekko] val bytestrings: Vector[ByteString1], val length: Int)
[error]               ^
[error] /Users/pj.fanning/code/pekko/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala:922:29: Calls to parameterless method toArray will be easy to mistake for calls to final override def toArray[B >: Byte](implicit arg0: scala.reflect.ClassTag[B]): Array[B], which has a single implicit parameter list.
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-overload, site=org.apache.pekko.util.ByteString
[error]   protected[ByteString] def toArray: Array[Byte] = toArray[Byte]
[error]                             ^
[error] /Users/pj.fanning/code/pekko/actor/src/main/scala-2.13/org/apache/pekko/util/ByteString.scala:1160:23: Calls to parameterless method toArray will be easy to mistake for calls to final override def toArray[B >: Byte](implicit arg0: scala.reflect.ClassTag[B]): Array[B], which has a single implicit parameter list.
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-overload, site=org.apache.pekko.util.CompactByteString
[error] sealed abstract class CompactByteString extends ByteString with Serializable {
[error]                       ^
[error] /Users/pj.fanning/code/pekko/actor/src/main/scala/org/apache/pekko/actor/Address.scala:78:79: method productHash in object MurmurHash3 is deprecated (since 2.13.17): use `caseClassHash` instead
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=deprecation, site=org.apache.pekko.actor.Address.hashCode, origin=scala.util.hashing.MurmurHash3.productHash, version=2.13.17
[error]   @transient override lazy val hashCode: Int = scala.util.hashing.MurmurHash3.productHash(this)
[error]                                                                               ^
[error] 6 errors found
[error] (actor / Compile / compileIncremental) Compilation failed

pekko-stream and pekko-testkit

[info] compiling 202 Scala sources and 4 Java sources to /Users/pj.fanning/code/pekko/stream/target/scala-2.13/classes ...
[error] /Users/pj.fanning/code/pekko/stream/src/main/scala/org/apache/pekko/stream/impl/QueueSource.scala:53:16: method createLogicAndMaterializedValue has an inferred structural type: (org.apache.pekko.stream.stage.GraphStageLogic with org.apache.pekko.stream.stage.OutHandler with org.apache.pekko.stream.scaladsl.SourceQueueWithComplete[T] with org.apache.pekko.stream.stage.StageLogging{def buffer: org.apache.pekko.stream.impl.Buffer[T]; def buffer_=(x$1: org.apache.pekko.stream.impl.Buffer[T]): Unit; def pendingOffers: org.apache.pekko.stream.impl.Buffer[org.apache.pekko.stream.impl.QueueSource.Offer[T]]; def pendingOffers_=(x$1: org.apache.pekko.stream.impl.Buffer[org.apache.pekko.stream.impl.QueueSource.Offer[T]]): Unit; def terminating: Boolean; def terminating_=(x$1: Boolean): Unit}, org.apache.pekko.stream.stage.GraphStageLogic with org.apache.pekko.stream.stage.OutHandler with org.apache.pekko.stream.scaladsl.SourceQueueWithComplete[T] with org.apache.pekko.stream.stage.StageLogging{def buffer: org.apache.pekko.stream.impl.Buffer[T]; def buffer_=(x$1: org.apache.pekko.stream.impl.Buffer[T]): Unit; def pendingOffers: org.apache.pekko.stream.impl.Buffer[org.apache.pekko.stream.impl.QueueSource.Offer[T]]; def pendingOffers_=(x$1: org.apache.pekko.stream.impl.Buffer[org.apache.pekko.stream.impl.QueueSource.Offer[T]]): Unit; def terminating: Boolean; def terminating_=(x$1: Boolean): Unit})
[error]   members that can be accessed with a reflective call: def buffer: org.apache.pekko.stream.impl.Buffer[T],def buffer_=(x$1: org.apache.pekko.stream.impl.Buffer[T]): Unit,def pendingOffers: org.apache.pekko.stream.impl.Buffer[org.apache.pekko.stream.impl.QueueSource.Offer[T]],def pendingOffers_=(x$1: org.apache.pekko.stream.impl.Buffer[org.apache.pekko.stream.impl.QueueSource.Offer[T]]): Unit,def terminating: Boolean,def terminating_=(x$1: Boolean): Unit
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-structural-type, site=org.apache.pekko.stream.impl.QueueSource.createLogicAndMaterializedValue
[error]   override def createLogicAndMaterializedValue(inheritedAttributes: Attributes) = {
[error]                ^
[error] /Users/pj.fanning/code/pekko/stream/src/main/scala/org/apache/pekko/stream/impl/SetupStage.scala:48:15: method createStageLogic has an inferred structural type: org.apache.pekko.stream.stage.GraphStageLogic{val subInlet: this.SubSinkInlet[U]; val subOutlet: this.SubSourceOutlet[T]}
[error]   members that can be accessed with a reflective call: val subInlet: this.SubSinkInlet[U],val subOutlet: this.SubSourceOutlet[T]
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-structural-type, site=org.apache.pekko.stream.impl.SetupFlowStage.createStageLogic
[error]   private def createStageLogic(matPromise: Promise[M]) = new GraphStageLogic(shape) {
[error]               ^
[error] /Users/pj.fanning/code/pekko/stream/src/main/scala/org/apache/pekko/stream/impl/SetupStage.scala:91:15: method createStageLogic has an inferred structural type: org.apache.pekko.stream.stage.GraphStageLogic{val subInlet: this.SubSinkInlet[T]}
[error]   members that can be accessed with a reflective call: val subInlet: this.SubSinkInlet[T]
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-structural-type, site=org.apache.pekko.stream.impl.SetupSourceStage.createStageLogic
[error]   private def createStageLogic(matPromise: Promise[M]) = new GraphStageLogic(shape) {
[error]               ^
[error] /Users/pj.fanning/code/pekko/stream/src/main/scala/org/apache/pekko/stream/impl/Sinks.scala:258:16: method createLogicAndMaterializedValue has an inferred structural type: (org.apache.pekko.stream.stage.GraphStageLogic with org.apache.pekko.stream.stage.InHandler{val buf: scala.collection.mutable.Builder[T,That with scala.collection.immutable.Iterable[_]]}, scala.concurrent.Future[That])
[error]   members that can be accessed with a reflective call: val buf: scala.collection.mutable.Builder[T,That with scala.collection.immutable.Iterable[_]]
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-structural-type, site=org.apache.pekko.stream.impl.SeqStage.createLogicAndMaterializedValue
[error]   override def createLogicAndMaterializedValue(inheritedAttributes: Attributes) = {
[error]                ^
[error] /Users/pj.fanning/code/pekko/stream/src/main/scala/org/apache/pekko/stream/impl/Sinks.scala:315:16: method createLogicAndMaterializedValue has an inferred structural type: (org.apache.pekko.stream.stage.GraphStageLogic with org.apache.pekko.stream.stage.InHandler with org.apache.pekko.stream.scaladsl.SinkQueueWithCancel[T]{val maxBuffer: Int; val buffer: org.apache.pekko.stream.impl.Buffer[scala.util.Try[Option[T]]]; val currentRequests: org.apache.pekko.stream.impl.Buffer[scala.concurrent.Promise[Option[T]]]; def sendDownstream(promise: scala.concurrent.Promise[Option[T]]): Unit}, org.apache.pekko.stream.stage.GraphStageLogic with org.apache.pekko.stream.stage.InHandler with org.apache.pekko.stream.scaladsl.SinkQueueWithCancel[T]{val maxBuffer: Int; val buffer: org.apache.pekko.stream.impl.Buffer[scala.util.Try[Option[T]]]; val currentRequests: org.apache.pekko.stream.impl.Buffer[scala.concurrent.Promise[Option[T]]]; def sendDownstream(promise: scala.concurrent.Promise[Option[T]]): Unit})
[error]   members that can be accessed with a reflective call: val maxBuffer: Int,val buffer: org.apache.pekko.stream.impl.Buffer[scala.util.Try[Option[T]]],val currentRequests: org.apache.pekko.stream.impl.Buffer[scala.concurrent.Promise[Option[T]]],def sendDownstream(promise: scala.concurrent.Promise[Option[T]]): Unit
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-structural-type, site=org.apache.pekko.stream.impl.QueueSink.createLogicAndMaterializedValue
[error]   override def createLogicAndMaterializedValue(inheritedAttributes: Attributes) = {
[error]                ^
[error] /Users/pj.fanning/code/pekko/stream/src/main/scala/org/apache/pekko/stream/impl/io/TcpStages.scala:67:16: method createLogicAndMaterializedValue has an inferred structural type: (org.apache.pekko.stream.stage.TimerGraphStageLogic with org.apache.pekko.stream.stage.StageLogging{implicit def self: org.apache.pekko.actor.ActorRef; val connectionFlowsAwaitingInitialization: java.util.concurrent.atomic.AtomicLong; def listener: org.apache.pekko.actor.ActorRef; def listener_=(x$1: org.apache.pekko.actor.ActorRef): Unit; val unbindPromise: scala.concurrent.Promise[Unit]; def unbindStarted: Boolean; def unbindStarted_=(x$1: Boolean): Unit}, scala.concurrent.Future[org.apache.pekko.stream.scaladsl.Tcp.ServerBinding])
[error]   members that can be accessed with a reflective call: implicit def self: org.apache.pekko.actor.ActorRef,val connectionFlowsAwaitingInitialization: java.util.concurrent.atomic.AtomicLong,def listener: org.apache.pekko.actor.ActorRef,def listener_=(x$1: org.apache.pekko.actor.ActorRef): Unit,val unbindPromise: scala.concurrent.Promise[Unit],def unbindStarted: Boolean,def unbindStarted_=(x$1: Boolean): Unit
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-structural-type, site=org.apache.pekko.stream.impl.io.ConnectionSourceStage.createLogicAndMaterializedValue
[error]   override def createLogicAndMaterializedValue(inheritedAttributes: Attributes, eagerMaterialzer: Materializer) = {
[error]                ^
[error] 6 errors found
[info] compiling 1 Scala source to /Users/pj.fanning/code/pekko/slf4j/target/scala-2.13/classes ...
[info] compiling 26 Scala sources and 3 Java sources to /Users/pj.fanning/code/pekko/testkit/target/scala-2.13/test-classes ...
[error] /Users/pj.fanning/code/pekko/testkit/src/test/scala/org/apache/pekko/testkit/metrics/MetricsKit.scala:193:7: value GcMetricsFilter has an inferred structural type: com.codahale.metrics.MetricFilter{val keyPattern: java.util.regex.Pattern}
[error]   members that can be accessed with a reflective call: val keyPattern: java.util.regex.Pattern
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-structural-type, site=org.apache.pekko.testkit.metrics.MetricsKit.GcMetricsFilter
[error]   val GcMetricsFilter = new MetricFilter {
[error]       ^
[error] one error found
[info] compiling 88 Scala sources to /Users/pj.fanning/code/pekko/actor-typed/target/scala-2.13/classes ...
[error] (stream / Compile / compileIncremental) Compilation failed
[error] (testkit / Test / compileIncremental) Compilation failed

We also have big trouble with scalatest - lots of these issues with our test code (one example)

[error] /Users/pj.fanning/code/pekko/testkit/src/test/scala/org/apache/pekko/testkit/AbstractSpec.scala:21:16: Usages of value an will be easy to mistake for calls to def an[T](implicit evidence$6: scala.reflect.ClassTag[T]): org.scalatest.matchers.dsl.ResultOfAnTypeInvocation[T], which has a single implicit parameter list.
[error] Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=lint-overload, site=org.apache.pekko.testkit.AbstractSpec
[error] abstract class AbstractSpec extends AnyWordSpecLike with Matchers with BeforeAndAfterEach

pjfanning avatar Aug 03 '25 18:08 pjfanning

Also:

[warn] /Users/pj.fanning/code/pekko/actor-tests/src/test/java/org/apache/pekko/japi/ThrowablesTest.java:28:46: java.lang.ThreadDeath in java.lang has been deprecated and marked for removal
[warn] ThreadDeath

pjfanning avatar Aug 03 '25 20:08 pjfanning

2.13.16 compilation of the project out of the box also gives fatal warning. 2.13.16 was added back in Jan.

I don't understand why the project is not buildable out of the box ... Were there green CI builds for that change?

GrafDiffusore avatar Aug 12 '25 16:08 GrafDiffusore

Specifically, targetSystemJdk := true and compiling on JDK 17 or 21 gives

[error] .../pekko/actor-typed/src/main/scala/org/apache/pekko/actor/typed/internal/LoggerClass.scala:29:53: class SecurityManager in package lang is deprecated (since 17)
...
[error]   private final class TrickySecurityManager extends SecurityManager {

GrafDiffusore avatar Aug 12 '25 17:08 GrafDiffusore

@GrafDiffusore we use Java 11 for release builds - see https://github.com/apache/pekko?tab=readme-ov-file#building-from-source

We do have CI jobs that build with other versions of Java. We do not use targetSystemJdk := true in any CI builds and have recently removed it from our main branch.

pjfanning avatar Aug 12 '25 17:08 pjfanning

You can also disable the build setting that makes compiler warnings fail the build. https://github.com/apache/pekko/blob/3f71d291573b6cb058549234e123a5d740a162d6/CONTRIBUTING.md?plain=1#L475

pjfanning avatar Aug 12 '25 18:08 pjfanning

@GrafDiffusore we use Java 11 for release builds - see https://github.com/apache/pekko?tab=readme-ov-file#building-from-source

We do have CI jobs that build with other versions of Java. We do not use targetSystemJdk := true in any CI builds and have recently removed it from our main branch.

❤️

Apologies for rough comments, I was a bit frustrated ... now that I checked out main branch I have project compiled fine, but I have another question -- why produced class files are of Java 8 byte-code level, although sbt tells that javac -target 17 is going to be used ?

pekko > show distributed-data / javacOptions
[info] * -source
[info] * 17
[info] * -target
[info] * 17
...
file distributed-data/target/scala-2.13/classes/org/apache/pekko/cluster/ddata/WriteAggregator.class 
distributed-data/target/scala-2.13/classes/org/apache/pekko/cluster/ddata/WriteAggregator.class: compiled Java class data, version 52.0 (Java 1.8)

GrafDiffusore avatar Aug 12 '25 20:08 GrafDiffusore

Scalac generates Java 8 compatible classes. Only Java classes are really affected by the javacOptions. Scalac - this a feature of Scalac and not under Pekko's control.

pjfanning avatar Aug 12 '25 21:08 pjfanning

Right. Indeed.

But then I having

> debug
> distributed-data / compile
...
[debug] [zinc] The Scala compiler is invoked with:
...
[debug] 	-language:higherKinds
[debug] 	release:17
[debug] 	-classpath
...

Strange thing here is that release should have a dash in front, if I'm not mistaken. Even stranger, for a manual run with a test source file:

tmp ~/bin/scala-2.13.16/bin/scalac release:17 S.scala
error: IO error while decoding release:17 with UTF-8: release:17 (No such file or directory)
Please try specifying another one using the -encoding option
1 error

So somehow sbt just ignores this setting ? ...

GrafDiffusore avatar Aug 12 '25 22:08 GrafDiffusore