diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-10-21 04:19:08 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-10-21 04:19:08 +1000 |
commit | bb05881595f5734855bba8f419706d26da9563c7 (patch) | |
tree | 003d2c5ecc49c8061151479abd06e7e8f42651c3 /src | |
parent | c99e53e8a05fc5d45f8e8a28da68d3977be65bfa (diff) | |
download | scala-bb05881595f5734855bba8f419706d26da9563c7.tar.gz scala-bb05881595f5734855bba8f419706d26da9563c7.tar.bz2 scala-bb05881595f5734855bba8f419706d26da9563c7.zip |
SI-9527 Fix NPE in ambiguous implicit error generation
In #4673, an annotation was added to allow customization of the
compiler error for ambigous implicits. This change had incorrect
assumptions about the shape of trees that would be generated during
implicit search, and failed to account for the results of eta expanded
methods when searching for a function type.
This commit:
- Uses the symbol from `ImpilcitInfo`, rather than calling
`Tree#symbol` which is fraught with the danger of returning a
null symbol for something other than an application.
- Adds a test for customized messages for a polymorphic, eta
expanded method, and generalizes `treeTypeArgs` to handle the
implicit tree of shape `{ (x: X) => f[A](x)}`.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index c9d3b3da96..b7c72f5373 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -1250,13 +1250,14 @@ trait ContextErrors { ) } - def treeTypeArgs(annotatedTree: Tree) = annotatedTree match { + def treeTypeArgs(annotatedTree: Tree): List[String] = annotatedTree match { case TypeApply(_, args) => args.map(_.toString) + case Block(_, Function(_, treeInfo.Applied(_, targs, _))) => targs.map(_.toString) // eta expansion, see neg/t9527b.scala case _ => Nil } context.issueAmbiguousError(AmbiguousImplicitTypeError(tree, - (tree1.symbol, tree2.symbol) match { + (info1.sym, info2.sym) match { case (ImplicitAmbiguousMsg(msg), _) => msg.format(treeTypeArgs(tree1)) case (_, ImplicitAmbiguousMsg(msg)) => msg.format(treeTypeArgs(tree2)) case (_, _) if isView => viewMsg |