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 /test | |
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 'test')
-rw-r--r-- | test/files/neg/t9527a.check | 7 | ||||
-rw-r--r-- | test/files/neg/t9527a.scala | 8 | ||||
-rw-r--r-- | test/files/neg/t9527b.check | 4 | ||||
-rw-r--r-- | test/files/neg/t9527b.scala | 9 |
4 files changed, 28 insertions, 0 deletions
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] + } +} + |