From 6cbb4d032b9ce402ceb15809d89e49401aace449 Mon Sep 17 00:00:00 2001 From: barkhorn Date: Sun, 5 Mar 2017 18:41:56 +0000 Subject: [PATCH] provide better error message in case mock function is assigned to a val. close #113 --- .../main/scala/org/scalamock/clazz/MockFunctionFinder.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/shared/src/main/scala/org/scalamock/clazz/MockFunctionFinder.scala b/core/shared/src/main/scala/org/scalamock/clazz/MockFunctionFinder.scala index fe270a3a..a63680af 100644 --- a/core/shared/src/main/scala/org/scalamock/clazz/MockFunctionFinder.scala +++ b/core/shared/src/main/scala/org/scalamock/clazz/MockFunctionFinder.scala @@ -50,7 +50,8 @@ object MockFunctionFinder { case Typed(expr, tpt) => transcribeTree(expr) case Function(vparams, body) => transcribeTree(body) case Apply(fun, args) => transcribeTree(fun) - case TypeApply(fun, args) => transcribeTree(fun, args.map(_.tpe)); + case TypeApply(fun, args) => transcribeTree(fun, args.map(_.tpe)) + case Ident(fun) => reportError(s"please declare '$fun' as MockFunctionx or StubFunctionx (e.g val $fun: MockFunction1[X, R] = ... if it has 1 parameter)") case _ => reportError( s"ScalaMock: Unrecognised structure: ${showRaw(tree)}." + "Please open a ticket at https://github.com/paulbutcher/ScalaMock/issues")