Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package object extends deprecated under -Xsource:3 not dotty #12886

Closed
som-snytt opened this issue Oct 5, 2023 · 7 comments · Fixed by scala/scala#10573
Closed

Package object extends deprecated under -Xsource:3 not dotty #12886

som-snytt opened this issue Oct 5, 2023 · 7 comments · Fixed by scala/scala#10573
Assignees
Labels
Milestone

Comments

@som-snytt
Copy link

som-snytt commented Oct 5, 2023

Reproduction steps

Scala version: 2.13.12

package object p extends Runnable {
  def run() = ()
}

then

$ scalac -Xsource:3 -d /tmp/sandbox po.scala
po.scala:2: error: package object inheritance is deprecated (https://github.com/scala/scala-dev/issues/441);
drop the `extends` clause or use a regular object instead
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
package object p extends Runnable {
                 ^
1 error

Problem

Dotty doesn't give a peep in 3.3.

eed3si9n/scalaxb#606

Notes

@eed3si9n
Copy link
Member

eed3si9n commented Oct 5, 2023

I'm doing some due diligence before removing the warning.

aaa/Protocols.scala

package aaa

trait Protocols:
  implicit lazy val fooOrdering: Ordering[example.Foo] = new Ordering[example.Foo]:
    def compare(a: example.Foo, b: example.Foo): Int = 0

  def something = 1

example/package.scala

package example

object `package` extends aaa.Protocols

case class Foo()

demo

and the trouble is that the package object doesn't seem to be part of the implicit scope?

sbt:foo> console
[info] compiling 3 Scala sources to /private/tmp/foo/target/scala-3.3.0/classes ...
Welcome to Scala 3.3.0 (1.8.0_352, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> List(example.Foo()).sorted
-- [E172] Type Error: ----------------------------------------------------------
1 |List(example.Foo()).sorted
  |                          ^
  |No implicit Ordering defined for B..
  |I found:
  |
  |    scala.math.Ordering.ordered[B](
  |      /* missing */summon[scala.math.Ordering.AsComparable[B]])
  |
  |But no implicit values were found that match type scala.math.Ordering.AsComparable[B]
  |
  |where:    B is a type variable with constraint >: example.Foo
  |.
  |
  |The following import might fix the problem:
  |
  |  import example.fooOrdering
  |
1 error found

so this demonstrates that:

  1. yes, Scala 3.3 has no issue with a package object with inheritance.
  2. in Scala 3.3, the power of inheritance doesn't reach as far as it did in Scala 2.13, at least for the purpose of Implicits without the import tax.

@som-snytt
Copy link
Author

som-snytt commented Oct 5, 2023

In fact, there is an Adriaan comment on the linked ticket somewhere that suggests the "package prefix" issue was his real concern, not merely inheritance. I'll consider instead having a Scala 2 flag to a) warn about that and b) change the behavior.

Possibly, -Xsource:3 warns only about changing behavior, -Xsource:3X changes the behavior.

scala/scala-dev#441 (comment)

The scratch for the itch would have been scala/scala-dev#446

I forgot that I'd commented there that -Xsource:3 was bored and looking for some excitement.

@lrytz lrytz added this to the 2.13.13 milestone Oct 12, 2023
@lrytz
Copy link
Member

lrytz commented Oct 12, 2023

Agree 👍 thanks for summarizing everything.

@som-snytt
Copy link
Author

Footnote, I tried -Xsource:3 (which means 3.0.0) for warning only and anything that compares higher for behavior, such as -Xsource:3-X (or 3.1 or 3.1-M1). Possibly, any "development build" label will compare higher. (Still need to nail it down.) The idea is that the option value remains an ordinary version string.

@lrytz
Copy link
Member

lrytz commented Nov 21, 2023

Removed the warning in scala/scala#10573.

Seth also suggested to introduce a warning under -Xsource:3 when an implicit is selected from package prefix.

@SethTisue
Copy link
Member

SethTisue commented Nov 21, 2023

when an implicit is selected from package prefix

Or, as Lukas counter-suggested, at definition site (when a package object defines an implicit)? I worry that warning at the use site might be too annoying if the implicit in question is coming from a library that the user doesn't control.

@som-snytt above when you wrote "warn about that" did you have one or the other approach in mind?

@som-snytt
Copy link
Author

I think I had the Seth solution in mind. I haven't had coffee yet. The spouse is yelling about something.

Oh, I see your question is, is that annoying? if a library defined an implicit in an old-fashioned way. Well, that will break under Scala 3, so the job in Scala 2 is to annoy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants