diff options
author | Martin Odersky <odersky@gmail.com> | 2017-03-08 22:06:22 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2017-03-08 22:06:35 +0100 |
commit | aa2f9078d76a21d828a06b8e324d31a502ee505c (patch) | |
tree | bf657e58c1a78357349def2309dd41c0cecdd9a1 /library | |
parent | 180dfdc7e81d632e599fb0a545025720e8000573 (diff) | |
download | dotty-aa2f9078d76a21d828a06b8e324d31a502ee505c.tar.gz dotty-aa2f9078d76a21d828a06b8e324d31a502ee505c.tar.bz2 dotty-aa2f9078d76a21d828a06b8e324d31a502ee505c.zip |
Drop special case around Function1
Now only Scala2 mode treats Function1's as implicit conversions. Instead we introduce
a new subclass ImplicitConverter of Function1, instances of which are turned into
implicit conversions.
Diffstat (limited to 'library')
-rw-r--r-- | library/src/dotty/DottyPredef.scala | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/library/src/dotty/DottyPredef.scala b/library/src/dotty/DottyPredef.scala index 12040e0f3..e78fa9239 100644 --- a/library/src/dotty/DottyPredef.scala +++ b/library/src/dotty/DottyPredef.scala @@ -36,4 +36,24 @@ object DottyPredef { implicit def eqNumFloat : Eq[Number, Float] = Eq implicit def eqDoubleNum: Eq[Double, Number] = Eq implicit def eqNumDouble: Eq[Number, Double] = Eq + + /** A class for implicit values that can serve as implicit conversions + * The implicit resolution algorithm will act as if there existed + * the additional implicit definition: + * + * def $implicitConversion[T, U](x: T)(c: ImplicitConverter[T, U]): U = c(x) + * + * However, the presence of this definition would slow down implicit search since + * its outermost type matches any pair of types. Therefore, implicit search + * contains a special case in `Implicits#discardForView` which emulates the + * conversion in a more efficient way. + * + * Note that this is a SAM class - function literals are automatically converted + * to `ImplicitConverter` values. + * + * Also note that in bootstrapped dotty, `Predef.<:<` should inherit from + * `ImplicitConverter`. This would cut the number of special cases in + * `discardForView` from two to one. + */ + abstract class ImplicitConverter[-T, +U] extends Function1[T, U] } |