diff options
author | Martin Odersky <odersky@gmail.com> | 2016-05-04 12:09:52 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-05-23 16:11:45 +0200 |
commit | 89540268e6c49fb92b9ca61249e46bb59981bf5a (patch) | |
tree | 5d7296175b7f27fd4243c61775bf262b84ea919f /src/dotty/tools/dotc/typer/Implicits.scala | |
parent | 039e20f3919d2ff4aa30a1f58314d0d0bff319c0 (diff) | |
download | dotty-89540268e6c49fb92b9ca61249e46bb59981bf5a.tar.gz dotty-89540268e6c49fb92b9ca61249e46bb59981bf5a.tar.bz2 dotty-89540268e6c49fb92b9ca61249e46bb59981bf5a.zip |
Downwards comparisons for implicit search and overloading resolution
Compare selected contravariant arguments as if they were covariant.
Which ones is explained in the doc comment for method `isAsSpecificValueType`
in Applications.scala.
This has the same motivation than what @paulp proposed around 2012. The solution is a bit
different from the one proposed then because it only affects top-level parameters.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Implicits.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Implicits.scala | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index d71d1956f..940170ceb 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -439,7 +439,19 @@ trait Implicits { self: Typer => result case result: AmbiguousImplicits => val deepPt = pt.deepenProto - if (deepPt ne pt) inferImplicit(deepPt, argument, pos) else result + if (deepPt ne pt) inferImplicit(deepPt, argument, pos) + else if (ctx.scala2Mode && !ctx.mode.is(Mode.OldOverloadingResolution)) { + inferImplicit(pt, argument, pos)(ctx.addMode(Mode.OldOverloadingResolution)) match { + case altResult: SearchSuccess => + ctx.migrationWarning( + s"According to new implicit resolution rules, this will be ambiguous:\n ${result.explanation}", + pos) + altResult + case _ => + result + } + } + else result case _ => assert(prevConstr eq ctx.typerState.constraint) result |