diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-10-18 07:22:58 -0700 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-10-18 07:22:58 -0700 |
commit | 54707cb45018170e31eb188a9a694ab9b0728f71 (patch) | |
tree | fae843355f051d9aed9b223ecf18c28bee63ecd9 /src | |
parent | 5b2c4644a23ffbe1c45df40bf3511aee71eb0fe2 (diff) | |
parent | 210dbc7887bc42eed4154de65d0ff5f46ca5ee58 (diff) | |
download | scala-54707cb45018170e31eb188a9a694ab9b0728f71.tar.gz scala-54707cb45018170e31eb188a9a694ab9b0728f71.tar.bz2 scala-54707cb45018170e31eb188a9a694ab9b0728f71.zip |
Merge pull request #3030 from xeno-by/topic/fundep-views
SI-3346 implicit parameters can now guide implicit view inference
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Implicits.scala | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index b30ae917d9..c19d861d23 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -579,10 +579,10 @@ trait Implicits { private def typedImplicit1(info: ImplicitInfo, isLocal: Boolean): SearchResult = { if (Statistics.canEnable) Statistics.incCounter(matchingImplicits) - val itree = atPos(pos.focus) { - // workaround for deficient context provided by ModelFactoryImplicitSupport#makeImplicitConstraints - val isScalaDoc = context.tree == EmptyTree + // workaround for deficient context provided by ModelFactoryImplicitSupport#makeImplicitConstraints + val isScalaDoc = context.tree == EmptyTree + val itree = atPos(pos.focus) { if (isLocal && !isScalaDoc) { // SI-4270 SI-5376 Always use an unattributed Ident for implicits in the local scope, // rather than an attributed Select, to detect shadowing. @@ -605,7 +605,23 @@ trait Implicits { atPos(itree.pos)(Apply(itree, List(Ident("<argument>") setType approximate(arg1)))), EXPRmode, approximate(arg2) - ) + ) match { + // try to infer implicit parameters immediately in order to: + // 1) guide type inference for implicit views + // 2) discard ineligible views right away instead of risking spurious ambiguous implicits + // + // this is an improvement of the state of the art that brings consistency to implicit resolution rules + // (and also helps fundep materialization to be applicable to implicit views) + // + // there's one caveat though. we need to turn this behavior off for scaladoc + // because scaladoc usually doesn't know the entire story + // and is just interested in views that are potentially applicable + // for instance, if we have `class C[T]` and `implicit def conv[T: Numeric](c: C[T]) = ???` + // then Scaladoc will give us something of type `C[T]`, and it would like to know + // that `conv` is potentially available under such and such conditions + case tree if isImplicitMethodType(tree.tpe) && !isScalaDoc => applyImplicitArgs(tree) + case tree => tree + } case _ => fallback } context.firstError match { // using match rather than foreach to avoid non local return. @@ -617,7 +633,7 @@ trait Implicits { if (Statistics.canEnable) Statistics.incCounter(typedImplicits) - val itree2 = if (isView) (itree1: @unchecked) match { case Apply(fun, _) => fun } + val itree2 = if (isView) treeInfo.dissectApplied(itree1).callee else adapt(itree1, EXPRmode, wildPt) typingStack.showAdapt(itree, itree2, pt, context) |