scala / bug

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

Extension method not found when using by-name parameter in presence of implicit conversion #12696

Open OndrejSpanel opened 1 year ago

OndrejSpanel commented 1 year ago

Reproduction steps

Scala version: 2.13.10

import scala.language.implicitConversions

implicit class OrObj[T <: AnyRef](a: T) {
  def || (b: =>T): T = if (a != null) a else b
}

implicit def objToBool[T <: AnyRef](x: T): Boolean = x != null

class C(x: String)

val a = new C("A")
val b = new C("B")

a || b

Problem

Produces error "value || is not a member of C".

Note:

Jasper-M commented 1 year ago

The strange part to me is that the implicit conversion is no longer ambiguous when you switch the parameter to by-value.

som-snytt commented 1 year ago

There is a glitch where Boolean ops are defined in the spec as by-name for purposes of laziness but do not actually have that signature. Also in Scala 2, f(=>A) is less specific than f(A), but not in 3. Perhaps the specificity of the results of the conversions determines the choice.