Skip to content

Commit

Permalink
make implicit resolution invocation more robust; just do not resolve …
Browse files Browse the repository at this point in the history
…implicits if that results in compiler errors
  • Loading branch information
pweisenburger committed Dec 15, 2017
1 parent c9b06cc commit 8434b0f
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions plugin/src/main/scala/dslparadise/typechecker/CallProcessor.scala
Expand Up @@ -2,6 +2,7 @@ package dslparadise
package typechecker

import scala.reflect.internal.Mode
import java.lang.reflect.InvocationTargetException

trait CallProcessor {
self: Analyzer with Typers =>
Expand Down Expand Up @@ -49,9 +50,32 @@ trait CallProcessor {
tree setType anonymousArgumentMethodType(argType, resultType)
tree.symbol setInfo tree.tpe

// only invoke implicit resolution if it does not result
// in compiler errors
val adaptTree = context inSilentMode {
try {
adaptToImplicitMethod.invoke(
this, tree.tpe, tree, Int box mode.bits, pt, original)
!context.reporter.hasErrors
}
catch {
// Since we faked the tree type, we may run into a situation
// where type-checking tries to treat the tree symbol as a
// method, which it is not, resulting in an exception.
// Assumingly, we should not resolve implicit values in this
// case.
case _: InvocationTargetException => false
}
}

// invoke existing implicit resolution
val adaptedTree = adaptToImplicitMethod.invoke(
this, tree.tpe, tree, Int box mode.bits, pt, original).asInstanceOf[Tree]
val adaptedTree =
if (adaptTree)
adaptToImplicitMethod.invoke(
this, tree.tpe, tree, Int box mode.bits, pt, original)
.asInstanceOf[Tree]
else
tree

// restore real type of the tree
tree setType realTreeType
Expand Down

0 comments on commit 8434b0f

Please sign in to comment.