diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-03-21 22:56:08 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2016-03-26 22:55:00 -0700 |
commit | 391e2843f420bb4686b974b18ac361c9bb49465c (patch) | |
tree | 580deff7251bd37f57fc4b432c6c772f55ff98f0 | |
parent | b0b0abab89f0c40ba3c45b4a1f7bada31040d55a (diff) | |
download | scala-391e2843f420bb4686b974b18ac361c9bb49465c.tar.gz scala-391e2843f420bb4686b974b18ac361c9bb49465c.tar.bz2 scala-391e2843f420bb4686b974b18ac361c9bb49465c.zip |
Don't adapt erroneous tree to SAM type.
Do not report second error. Go straight to the exit.
Based on review by Jason.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 4 | ||||
-rw-r--r-- | test/files/neg/sammy_error.check | 4 | ||||
-rw-r--r-- | test/files/neg/sammy_error.scala | 7 |
3 files changed, 13 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 3b826ae2e5..cd5759f40f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1074,7 +1074,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper // we know `!(tree.tpe <:< pt)`; try to remedy if there's a sam for pt val sam = samMatchingFunction(tree, pt) // this implies tree.isInstanceOf[Function] - if (sam.exists) { + if (sam.exists && !tree.tpe.isErroneous) { val samTree = adaptToSAM(sam, tree.asInstanceOf[Function], pt, mode) if (samTree ne EmptyTree) return samTree } @@ -2794,7 +2794,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper EmptyTree } } catch { - case e@(_: NoInstance | _: TypeError) => // TODO: we get here whenever pt contains a wildcardtype??? + case e@(_: NoInstance | _: TypeError) => debuglog(s"Error during SAM synthesis: could not define type $pt using ${fun.tpe} <:< ${pt memberInfo sam} (for $sam)\n$e") EmptyTree } diff --git a/test/files/neg/sammy_error.check b/test/files/neg/sammy_error.check new file mode 100644 index 0000000000..f14ac7e3a2 --- /dev/null +++ b/test/files/neg/sammy_error.check @@ -0,0 +1,4 @@ +sammy_error.scala:6: error: missing parameter type + foo(x => x) // should result in only one error (the second one stemmed from adapting to SAM when the tree was erroneous) + ^ +one error found diff --git a/test/files/neg/sammy_error.scala b/test/files/neg/sammy_error.scala new file mode 100644 index 0000000000..dbddebf325 --- /dev/null +++ b/test/files/neg/sammy_error.scala @@ -0,0 +1,7 @@ +trait F1[A, B] { def apply(a: A): B } + +class Test { + def foo[A](f1: F1[A, A]) = f1 + + foo(x => x) // should result in only one error (the second one stemmed from adapting to SAM when the tree was erroneous) +} |