Compilation error in Scala 3

Scala 2 version of the code that compiles - Scastie - An interactive playground for Scala

Same code in Scala 3 does not compile - Scastie - An interactive playground for Scala

What is the reason for not allowing this in Scala 3?

2 Likes

My intuition is that Scala 3 does the right thing - if I mark the constructor private, I probably want the generated apply() to be private, too. Otherwise it should be marked private[Foo].

Perhaps a manifestation of this issue? At least the -Xsource options mentioned there seem to make this fail in 2.13, as well.

4 Likes

UPDATE: This code creates an infinite loop on the apply method. Adding “new” is required. Please see my reply below for the fixed Scastie.

Here’s the code that “cures” the issue in Scala 3:

I think you made Zoo.apply loop infinitely.

1 Like

Ah. I think you may be right. Do I need to put “new” in front of it, like this?

Adding “new” seemed to work.

1 Like