scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Unexpected "constructor modifiers are assumed by synthetic `apply` method" #12915

Closed LuciferYang closed 7 months ago

LuciferYang commented 7 months ago

Reproduction steps

Scala version:2.13.12 with -Xsource:3

Welcome to Scala 2.13.12 (OpenJDK 64-Bit Server VM, Java 17.0.9).
Type in expressions for evaluation. Or try :help.

scala> :paste
// Entering paste mode (ctrl-D to finish)

import java.net.URI

case class SparkPath private (private val underlying: String) {
  def copy(underlying: String = this.underlying): SparkPath = SparkPath(underlying)
}

object SparkPath {
  def apply(underlying: String): SparkPath = new SparkPath(underlying)
}

// Exiting paste mode, now interpreting.

case class SparkPath private (private val underlying: String) {
           ^
<pastie>:3: error: constructor modifiers are assumed by synthetic `apply` method
Scala 3 migration messages are errors under -Xsource:3. Use -Wconf / @nowarn to filter them or add -Xmigration to demote them to warnings.
Applicable -Wconf / @nowarn filters for this fatal warning: msg=<part of the message>, cat=scala3-migration, site=SparkPath

Problem

I'm not sure if this is a bug, but besides adding @nowarn or removing the private modifier from the constructor, how should I define the apply method to avoid the above compilation error?

som-snytt commented 7 months ago

Thanks for the report and sorry for the misdirection. Fix and improvement in "future versions" forthcoming.

Duplicates https://github.com/scala/bug/issues/12883

LuciferYang commented 7 months ago

Thanks @som-snytt ~