This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Wrong implicit conversion ambiguity

No replies
Sciss
Joined: 2008-12-17,
User offline. Last seen 28 weeks 5 days ago.

hi,

i am having an ambiguity problem with implicit conversions:

// ------ 1 ------
package de.sciss
package object synth {
implicit def enrichFloat( x: Float ) = RichFloat( x )
}

// ------ 2 ------
package de.sciss.synth
final case class RichFloat private[synth]( f: Float ) {
def min( b: Constant ) : Constant = cn.min( b )
def min( b: GE ) : GE = cn.min( b )
}

scala> 20f.min(SinOsc.kr)

:25: error: type mismatch;
found : Float
required: ?{val min: ?}
Note that implicit conversions are not applicable because they are ambiguous:
both method floatWrapper in object Predef of type (x: Float)scala.runtime.RichFloat
and method enrichFloat in package synth of type (x: Float)de.sciss.synth.RichFloat
are possible conversion functions from Float to ?{val min: ?}
20f.min(SinOsc.kr)
^

i don't understand the problem! min in scala.runtime.RichFloat is defined as

• def min(y: Float): Float

and there are no implicit conversions back neither from Constant nor from GE to Float. so there is only one possible solution for 20f.min(SinOsc.kr).

and in general: is it possible to throw out the implicits from scala.runtime, they are really getting on my nerves? like import scala.runtime.{ _ => /dev/null )?

thanks, -sciss-

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland