Scala 3 compile issue (code that compiles in Scala 2.12/2.13)

Hi everyone,

I’m trying to add Scala 3 build support to one of the Apache Pekko libs. I’ve supported Scala 3 in a few libs before but the compile issue that I’m getting here has me confused.

I’ve reduced the issue to this scastie example - Scastie - An interactive playground for Scala.

The compile issue is:

object MultiResult in object ProducerMessage does not take parameters

It compiles on in Scala 2.13.

MultiResult is case class with type parameters - so I’m not sure why Scala 3.2/3.3-rcs don’t recognise this:
case class MultiResult[K, V, PassThrough]

Any pointers would be appreciated.

I think there must have been a change in the way that scala3 deals with case class generation. When you replace MultiResult with new MultiResult you get the following error

constructor MultiResult cannot be accessed as a member of Playground.ProducerMessage.MultiResult from class DefaultProducerStageLogic.

which makes sense since you marked it has private. Perhaps you have to manually define an apply to achieve this?

Thanks - that makes sense. The compile works if I make that constructor package private instead of fully private.

This is a famous or “infamous” issue.

It was not an easy search for me, so for the record:

the topic

the Scala 2 fix

If anyone is interested, I found the link by adding “tpolecat” to the search, as I remembered that abstract case class is a tpolecatism, or tpolecatechism I guess is the right word.

In Scala 2, unless otherwise constrained, always use -Xsource:3 to achieve further hints about whether your code will compile the same (we abjure here any petty notion of correctness).