|
[#628] |
project: compiler |
priority: low |
category: bug |
|
submitter |
assigned to |
status |
date submitted |
|
Lex |
Martin |
fixed |
2006-06-19 14:30:57.0 |
subject |
implicit conversion of (val * something) |
code |
object Test {
abstract class Unit
object NoUnit extends Unit
object Hour extends Unit
case class Measure(scalar: Double, unit: Unit) {
def *(newUnit: Unit) = Measure(scalar, newUnit)
}
implicit def double2Measure(scalar: Double) =
Measure(scalar, NoUnit)
def main(args: Array[String]): scala.Unit = {
Console.println("3.0 * Hour = " + (3.0 * Hour))
}
}
|
what happened |
/home/lex/eclipse/workspace/scala2/test/files/run/impconvtimes.scala:15 error: overloaded method value * wi\
th alternatives (scala.Double)scala.Double (scala.Float)scala.Double (scala.Long)scala.Double \
(scala.Int)scala.Double (scala.Char)scala.Double (scala.Short)scala.Double (scala.Byte)scala.D\
ouble cannot be applied to (Test.this.Hour.type)
Console.println("3.0 * Hour = " + (3.0 * Hour))
^
one error found
|
what expected |
It would be nice if this worked, although granted it is a corner case. The value could be converted uing double2Measure. If you change every "*" to "***", then it does work.
The question is: do implicit conversions of the receiver happen when there is (1) no method with the correct name, or (2) no type-compatible method with the correct name. It would be nice if it was (2). |
[back to overview] |