summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth Tisue <seth@tisue.net>2015-10-27 08:48:46 -0400
committerSeth Tisue <seth@tisue.net>2015-10-27 08:48:46 -0400
commited2d7a1f3f776a3e49f66f3f0c7a4a3eb49f1443 (patch)
tree4d2167a7f2848cd9d16f22d82324e38f053db7e6
parentd790277ee4a73ff09efb599fde88d3e408b239de (diff)
parentbb05881595f5734855bba8f419706d26da9563c7 (diff)
downloadscala-ed2d7a1f3f776a3e49f66f3f0c7a4a3eb49f1443.tar.gz
scala-ed2d7a1f3f776a3e49f66f3f0c7a4a3eb49f1443.tar.bz2
scala-ed2d7a1f3f776a3e49f66f3f0c7a4a3eb49f1443.zip
Merge pull request #4808 from retronym/ticket/9527
SI-9527 Fix NPE in ambiguous implicit error generation
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala5
-rw-r--r--test/files/neg/t9527a.check7
-rw-r--r--test/files/neg/t9527a.scala8
-rw-r--r--test/files/neg/t9527b.check4
-rw-r--r--test/files/neg/t9527b.scala9
5 files changed, 31 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
diff --git a/test/files/neg/t9527a.check b/test/files/neg/t9527a.check
new file mode 100644
index 0000000000..e756518bed
--- /dev/null
+++ b/test/files/neg/t9527a.check
@@ -0,0 +1,7 @@
+t9527a.scala:5: error: ambiguous implicit values:
+ both method f in class C of type (x: Int)String
+ and method g in class C of type (x: Int)String
+ match expected type Int => String
+ implicitly[Int => String]
+ ^
+one error found
diff --git a/test/files/neg/t9527a.scala b/test/files/neg/t9527a.scala
new file mode 100644
index 0000000000..35c58fc9a6
--- /dev/null
+++ b/test/files/neg/t9527a.scala
@@ -0,0 +1,8 @@
+class C {
+ implicit def f(x: Int): String = "f was here"
+ implicit def g(x: Int): String = "f was here"
+ def test: Unit = {
+ implicitly[Int => String]
+ }
+}
+
diff --git a/test/files/neg/t9527b.check b/test/files/neg/t9527b.check
new file mode 100644
index 0000000000..4529ec83ea
--- /dev/null
+++ b/test/files/neg/t9527b.check
@@ -0,0 +1,4 @@
+t9527b.scala:6: error: msg A=Nothing
+ implicitly[Int => String]
+ ^
+one error found
diff --git a/test/files/neg/t9527b.scala b/test/files/neg/t9527b.scala
new file mode 100644
index 0000000000..b40a4dca9e
--- /dev/null
+++ b/test/files/neg/t9527b.scala
@@ -0,0 +1,9 @@
+class C {
+ @annotation.implicitAmbiguous("msg A=${A}")
+ implicit def f[A](x: Int): String = "f was here"
+ implicit def g(x: Int): String = "f was here"
+ def test: Unit = {
+ implicitly[Int => String]
+ }
+}
+