SLC: Replace *Ops conversions by direct extension methods

PR Replace *Ops conversions by direct extension methods by halotukozak · Pull Request #26637 · scala/scala3 · GitHub

I propose to deprecate the implicit conversions, which was introduced to enable a’la extension method syntax. Currently, regular extension methods fit better. Similar to Replace runtime.Rich* implicits on primitives by direct extension methods. by sjrd · Pull Request #23872 · scala/scala3 · GitHub

e.g.

implicit def mkNumericOps(lhs: T): IntegralOps = new IntegralOps(lhs)

there is a one design question: should the extension methods be on the top-level or in the type class?

I’ve chosen the second one, but I don’t have a strong opinion.

Current draft doesn’t break binary compatibility, but it does break the source one (only if someone extends the TC and it’s not a problem in minor release, isn’t it?).
Inner extension methods in several instances bring the method name clash (they have to be marked with @targetName) but they allow to omit all the redundant bridges like this:

extension [T: Ops as ops](t: T)
  def meth = ops.meth(t)

However, with top-level extensions, there is a problem with overloading (e.g. math.max vs math.max for Ordering)

5 Likes