Closed som-snytt closed 5 months ago
I'm doing some due diligence before removing the warning.
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
package example
object `package` extends aaa.Protocols
case class Foo()
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:
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.
https://github.com/scala/scala-dev/issues/441#issuecomment-455270478
The scratch for the itch would have been https://github.com/scala/scala-dev/issues/446
I forgot that I'd commented there that -Xsource:3
was bored and looking for some excitement.
Agree 👍 thanks for summarizing everything.
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.
Removed the warning in https://github.com/scala/scala/pull/10573.
Seth also suggested to introduce a warning under -Xsource:3
when an implicit is selected from package prefix.
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?
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.
Reproduction steps
Scala version: 2.13.12
then
Problem
Dotty doesn't give a peep in 3.3.
https://github.com/eed3si9n/scalaxb/issues/606
Notes