Open noresttherein opened 1 year ago
"fixed in Scala 3" in the sense that the compiler accepts the extension
equivalent:
extension (self: Int)
def squared: Int = self * self
def avg(other: Int): Int = math.sqrt(squared * other.squared).toInt
Note that it is explicit for extensions. If it could be made to work for implicit class, it would require a spec.
perhaps it's sort of obvious, but for the record, in Scala 2 the workaround is to write out the call to the conversion yourself, so
def avg(other: Int): Int =
math.sqrt(squared * Extension(other).squared).toInt
Is the behavior according to the spec? Should the spec be clarified? Scala 3 does the same, it doesn't infer a view if the desired member is private. Changing this might have a bad impact on compiler performance.
https://www.scala-lang.org/files/archive/spec/2.13/07-implicits.html#views
I missed lrytz's previous point. The spec doesn't say that the member provided by the implicit must be accessible. (If two competing conversions offer a public and a private member respectively, the public is chosen and the private ignore, instead of ambiguity.)
Reproduction steps
Scala version: 2.13.10
Problem
Would be nice if implicit conversions triggered for all methods accessible in a given scope.