diff options
author | Martin Odersky <odersky@gmail.com> | 2015-11-01 16:08:46 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-11-01 16:08:46 +0100 |
commit | 5ed617b9ac205b831ec69b782472b1afc5752378 (patch) | |
tree | eab7d1dd8608a633222ef53b4005364eca3b2226 /src/dotty/tools/dotc/core/Types.scala | |
parent | 08e880231ff5facd55a80bed0391b22fe85a9f44 (diff) | |
download | dotty-5ed617b9ac205b831ec69b782472b1afc5752378.tar.gz dotty-5ed617b9ac205b831ec69b782472b1afc5752378.tar.bz2 dotty-5ed617b9ac205b831ec69b782472b1afc5752378.zip |
Better handling of implicits over numeric types.
Compiling scala.math.BigDecimal and scala.math.BigInteger shows a problem.
The conversion `int2bigInt` is not applicable to a Byte because `Byte -> Int`
requires another implicit conversion.
We fix that by using a new method relaxed_<:< for implicit compatibility checks,
which always admits numeric widenings.
This leads to another problem. Now the conversions
implicit def byteToInt(x: Byte): Int
implicit def byteToShort(x: Byte): Short
are ambiguous when we try to convert from Byte to Int.
We fix that by adding a "tie-break" to implicit search
where if several methods match a numeric value result type
and all have numeric value types as result types, we
pick the numerically largest type that matches.
Diffstat (limited to 'src/dotty/tools/dotc/core/Types.scala')
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 58a6d226d..05fb963f9 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -606,7 +606,7 @@ object Types { } /** Is this type a primitive value type which can be widened to the primitive value type `that`? */ - def isValueSubType(that: Type)(implicit ctx: Context) = widenExpr match { + def isValueSubType(that: Type)(implicit ctx: Context) = widen match { case self: TypeRef if defn.ScalaValueClasses contains self.symbol => that.widenExpr match { case that: TypeRef if defn.ScalaValueClasses contains that.symbol => @@ -618,6 +618,9 @@ object Types { false } + def relaxed_<:<(that: Type)(implicit ctx: Context) = + (this <:< that) || (this isValueSubType that) + /** Is this type a legal type for a member that overrides another * member of type `that`? This is the same as `<:<`, except that * the types ()T and => T are identified, and T is seen as overriding |