aboutsummaryrefslogtreecommitdiff
path: root/tests/new
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-11-01 16:08:46 +0100
committerMartin Odersky <odersky@gmail.com>2015-11-01 16:08:46 +0100
commit5ed617b9ac205b831ec69b782472b1afc5752378 (patch)
treeeab7d1dd8608a633222ef53b4005364eca3b2226 /tests/new
parent08e880231ff5facd55a80bed0391b22fe85a9f44 (diff)
downloaddotty-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 'tests/new')
-rw-r--r--tests/new/implicits.scala9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/new/implicits.scala b/tests/new/implicits.scala
new file mode 100644
index 000000000..1a3e0b4da
--- /dev/null
+++ b/tests/new/implicits.scala
@@ -0,0 +1,9 @@
+object Test {
+
+ class X(i: Int)
+
+ implicit def int2x(i: Int): X = new X(i)
+
+ val x: X = Byte.MinValue
+
+}