From 3faa2eedd8b9f58f29a5aeed710ffb91ec0f860b Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Fri, 6 Dec 2013 21:32:52 +0100 Subject: [nomaster] better error messages for various macro definition errors backport of 1d3ec4e708154ec05554f540d7d68ed55dc12426 --- src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala | 10 +++++++--- test/files/neg/macro-invalidimpl-f.check | 2 +- test/files/neg/macro-invalidimpl-g.check | 2 +- test/files/neg/macro-invalidret-nontree.check | 2 +- test/files/neg/macro-invalidret-nonuniversetree.check | 2 +- test/files/neg/macro-invalidsig-context-bounds.check | 5 +---- test/files/neg/macro-invalidsig-ctx-badargc.check | 2 +- test/files/neg/macro-invalidsig-ctx-badtype.check | 2 +- test/files/neg/macro-invalidsig-ctx-badvarargs.check | 2 +- test/files/neg/macro-invalidsig-ctx-noctx.check | 2 +- test/files/neg/macro-invalidsig-implicit-params.check | 5 +---- test/files/neg/macro-invalidsig-params-badargc.check | 2 +- test/files/neg/macro-invalidsig-params-badtype.check | 2 +- test/files/neg/macro-invalidsig-params-badvarargs.check | 2 +- test/files/neg/macro-invalidsig-params-namemismatch.check | 2 +- test/files/neg/macro-invalidsig-tparams-badtype.check | 2 +- test/files/neg/macro-invalidsig-tparams-notparams-a.check | 2 +- test/files/neg/macro-invalidsig-tparams-notparams-b.check | 2 +- test/files/neg/t5689.check | 2 +- 19 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index 5d6d094b44..a7b0e47214 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -1294,7 +1294,7 @@ trait ContextErrors { private def compatibilityError(message: String) = implRefError( - "macro implementation has wrong shape:"+ + "macro implementation has incompatible shape:"+ "\n required: " + showMeth(rparamss, rret, abbreviate = true) + "\n found : " + showMeth(aparamss, aret, abbreviate = false) + "\n" + message) @@ -1328,7 +1328,11 @@ trait ContextErrors { def MacroImplOverloadedError() = implRefError("macro implementation cannot be overloaded") - def MacroImplWrongNumberOfTypeArgumentsError(macroImplRef: Tree) = implRefError(typer.TyperErrorGen.TypedApplyWrongNumberOfTpeParametersErrorMessage(macroImplRef)) + def MacroImplWrongNumberOfTypeArgumentsError(macroImplRef: Tree) = { + val MacroImplReference(owner, meth, targs) = macroImplRef + val diagnostic = if (meth.typeParams.length > targs.length) "has too few type arguments" else "has too many arguments" + implRefError(s"macro implementation reference $diagnostic for " + treeSymTypeMsg(macroImplRef)) + } def MacroImplNotStaticError() = implRefError("macro implementation must be in statically accessible object") @@ -1336,7 +1340,7 @@ trait ContextErrors { // aXXX (e.g. aparams) => characteristics of the macro impl ("a" stands for "actual") // rXXX (e.g. rparams) => characteristics of a reference macro impl signature synthesized from the macro def ("r" stands for "reference") - def MacroImplNonTagImplicitParameters(params: List[Symbol]) = compatibilityError("macro implementations cannot have implicit parameters other than WeakTypeTag evidences") + def MacroImplNonTagImplicitParameters(params: List[Symbol]) = implRefError("macro implementations cannot have implicit parameters other than WeakTypeTag evidences") def MacroImplParamssMismatchError() = compatibilityError("number of parameter sections differ") diff --git a/test/files/neg/macro-invalidimpl-f.check b/test/files/neg/macro-invalidimpl-f.check index 4e5851f566..8820e05152 100644 --- a/test/files/neg/macro-invalidimpl-f.check +++ b/test/files/neg/macro-invalidimpl-f.check @@ -1,4 +1,4 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: +Macros_Test_2.scala:2: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context)(): c.Expr[Unit] found : (c: scala.reflect.macros.Context): c.Expr[Unit] number of parameter sections differ diff --git a/test/files/neg/macro-invalidimpl-g.check b/test/files/neg/macro-invalidimpl-g.check index 7342f7336f..c063803723 100644 --- a/test/files/neg/macro-invalidimpl-g.check +++ b/test/files/neg/macro-invalidimpl-g.check @@ -1,4 +1,4 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: +Macros_Test_2.scala:2: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context): c.Expr[Unit] found : (c: scala.reflect.macros.Context)(): c.Expr[Unit] number of parameter sections differ diff --git a/test/files/neg/macro-invalidret-nontree.check b/test/files/neg/macro-invalidret-nontree.check index 6d8336d06d..74e6f33339 100644 --- a/test/files/neg/macro-invalidret-nontree.check +++ b/test/files/neg/macro-invalidret-nontree.check @@ -1,4 +1,4 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: +Macros_Test_2.scala:2: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] found : (c: scala.reflect.macros.Context): Int type mismatch for return type: Int does not conform to c.Expr[Any] diff --git a/test/files/neg/macro-invalidret-nonuniversetree.check b/test/files/neg/macro-invalidret-nonuniversetree.check index 089bfd0dc9..81c4114ce0 100644 --- a/test/files/neg/macro-invalidret-nonuniversetree.check +++ b/test/files/neg/macro-invalidret-nonuniversetree.check @@ -1,4 +1,4 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: +Macros_Test_2.scala:2: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] found : (c: scala.reflect.macros.Context): reflect.runtime.universe.Literal type mismatch for return type: reflect.runtime.universe.Literal does not conform to c.Expr[Any] diff --git a/test/files/neg/macro-invalidsig-context-bounds.check b/test/files/neg/macro-invalidsig-context-bounds.check index 43b8c23b35..cbb2b06892 100644 --- a/test/files/neg/macro-invalidsig-context-bounds.check +++ b/test/files/neg/macro-invalidsig-context-bounds.check @@ -1,7 +1,4 @@ -Macros_Test_1.scala:2: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context): c.Expr[Any] - found : (c: scala.reflect.macros.Context)(implicit evidence$2: Numeric[U]): c.universe.Literal -macro implementations cannot have implicit parameters other than WeakTypeTag evidences +Macros_Test_1.scala:2: error: macro implementations cannot have implicit parameters other than WeakTypeTag evidences def foo[U] = macro Impls.foo[U] ^ one error found diff --git a/test/files/neg/macro-invalidsig-ctx-badargc.check b/test/files/neg/macro-invalidsig-ctx-badargc.check index 1c14072a94..7e8bcbaf74 100644 --- a/test/files/neg/macro-invalidsig-ctx-badargc.check +++ b/test/files/neg/macro-invalidsig-ctx-badargc.check @@ -1,4 +1,4 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: +Macros_Test_2.scala:2: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] found : : Nothing number of parameter sections differ diff --git a/test/files/neg/macro-invalidsig-ctx-badtype.check b/test/files/neg/macro-invalidsig-ctx-badtype.check index 340ace6a38..837ec3e496 100644 --- a/test/files/neg/macro-invalidsig-ctx-badtype.check +++ b/test/files/neg/macro-invalidsig-ctx-badtype.check @@ -1,4 +1,4 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: +Macros_Test_2.scala:2: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] found : (c: scala.reflect.api.Universe): Nothing type mismatch for parameter c: scala.reflect.macros.Context does not conform to scala.reflect.api.Universe diff --git a/test/files/neg/macro-invalidsig-ctx-badvarargs.check b/test/files/neg/macro-invalidsig-ctx-badvarargs.check index a6478f03e3..a96421a8c4 100644 --- a/test/files/neg/macro-invalidsig-ctx-badvarargs.check +++ b/test/files/neg/macro-invalidsig-ctx-badvarargs.check @@ -1,4 +1,4 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: +Macros_Test_2.scala:2: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] found : (cs: scala.reflect.macros.Context*): Nothing types incompatible for parameter cs: corresponding is not a vararg parameter diff --git a/test/files/neg/macro-invalidsig-ctx-noctx.check b/test/files/neg/macro-invalidsig-ctx-noctx.check index b7dc9a449b..fd3632eb9b 100644 --- a/test/files/neg/macro-invalidsig-ctx-noctx.check +++ b/test/files/neg/macro-invalidsig-ctx-noctx.check @@ -1,4 +1,4 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: +Macros_Test_2.scala:2: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context)(x: c.Expr[Any]): c.Expr[Any] found : (c: scala.reflect.macros.Context): Nothing number of parameter sections differ diff --git a/test/files/neg/macro-invalidsig-implicit-params.check b/test/files/neg/macro-invalidsig-implicit-params.check index f210eb8a32..900098fd98 100644 --- a/test/files/neg/macro-invalidsig-implicit-params.check +++ b/test/files/neg/macro-invalidsig-implicit-params.check @@ -1,7 +1,4 @@ -Impls_Macros_1.scala:18: error: macro implementation has wrong shape: - required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Unit] - found : (c: scala.reflect.macros.Context)(implicit x: c.Expr[Int]): c.Expr[Unit] -macro implementations cannot have implicit parameters other than WeakTypeTag evidences +Impls_Macros_1.scala:18: error: macro implementations cannot have implicit parameters other than WeakTypeTag evidences def foo_targs[U](x: Int) = macro Impls.foo_targs[T, U] ^ one error found diff --git a/test/files/neg/macro-invalidsig-params-badargc.check b/test/files/neg/macro-invalidsig-params-badargc.check index 3f6d815b8e..bb26b24f80 100644 --- a/test/files/neg/macro-invalidsig-params-badargc.check +++ b/test/files/neg/macro-invalidsig-params-badargc.check @@ -1,4 +1,4 @@ -Impls_Macros_1.scala:8: error: macro implementation has wrong shape: +Impls_Macros_1.scala:8: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Any] found : (c: scala.reflect.macros.Context)(x: c.Expr[Int], y: c.Expr[Int]): Nothing parameter lists have different length, found extra parameter y: c.Expr[Int] diff --git a/test/files/neg/macro-invalidsig-params-badtype.check b/test/files/neg/macro-invalidsig-params-badtype.check index 3ec40d7e5b..82276141a4 100644 --- a/test/files/neg/macro-invalidsig-params-badtype.check +++ b/test/files/neg/macro-invalidsig-params-badtype.check @@ -1,4 +1,4 @@ -Impls_Macros_1.scala:8: error: macro implementation has wrong shape: +Impls_Macros_1.scala:8: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context)(x: c.Expr[Int]): c.Expr[Any] found : (c: scala.reflect.macros.Context)(x: c.universe.Tree): Nothing type mismatch for parameter x: c.Expr[Int] does not conform to c.universe.Tree diff --git a/test/files/neg/macro-invalidsig-params-badvarargs.check b/test/files/neg/macro-invalidsig-params-badvarargs.check index 50607ff52d..cb4d2d91b1 100644 --- a/test/files/neg/macro-invalidsig-params-badvarargs.check +++ b/test/files/neg/macro-invalidsig-params-badvarargs.check @@ -1,4 +1,4 @@ -Impls_Macros_1.scala:8: error: macro implementation has wrong shape: +Impls_Macros_1.scala:8: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] found : (c: scala.reflect.macros.Context)(xs: c.Expr[Int]*): Nothing parameter lists have different length, required extra parameter y: c.Expr[Int] diff --git a/test/files/neg/macro-invalidsig-params-namemismatch.check b/test/files/neg/macro-invalidsig-params-namemismatch.check index 4029bc8129..82612a94d3 100644 --- a/test/files/neg/macro-invalidsig-params-namemismatch.check +++ b/test/files/neg/macro-invalidsig-params-namemismatch.check @@ -1,4 +1,4 @@ -Impls_Macros_1.scala:8: error: macro implementation has wrong shape: +Impls_Macros_1.scala:8: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context)(x: c.Expr[Int], y: c.Expr[Int]): c.Expr[Any] found : (c: scala.reflect.macros.Context)(y: c.Expr[Int], x: c.Expr[Int]): Nothing parameter names differ: x != y diff --git a/test/files/neg/macro-invalidsig-tparams-badtype.check b/test/files/neg/macro-invalidsig-tparams-badtype.check index e9f3547133..273d011412 100644 --- a/test/files/neg/macro-invalidsig-tparams-badtype.check +++ b/test/files/neg/macro-invalidsig-tparams-badtype.check @@ -1,4 +1,4 @@ -Macros_Test_2.scala:2: error: macro implementation has wrong shape: +Macros_Test_2.scala:2: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context): c.Expr[Any] found : (c: scala.reflect.macros.Context)(U: c.universe.Type): Nothing number of parameter sections differ diff --git a/test/files/neg/macro-invalidsig-tparams-notparams-a.check b/test/files/neg/macro-invalidsig-tparams-notparams-a.check index 61a5628b7e..c73125963f 100644 --- a/test/files/neg/macro-invalidsig-tparams-notparams-a.check +++ b/test/files/neg/macro-invalidsig-tparams-notparams-a.check @@ -1,4 +1,4 @@ -Macros_Test_2.scala:2: error: wrong number of type parameters for method foo: [U](c: scala.reflect.macros.Context)(implicit evidence$1: c.WeakTypeTag[U])Nothing +Macros_Test_2.scala:2: error: macro implementation reference has too few type arguments for method foo: [U](c: scala.reflect.macros.Context)(implicit evidence$1: c.WeakTypeTag[U])Nothing def foo = macro Impls.foo ^ one error found diff --git a/test/files/neg/macro-invalidsig-tparams-notparams-b.check b/test/files/neg/macro-invalidsig-tparams-notparams-b.check index a605af6beb..e3d45055de 100644 --- a/test/files/neg/macro-invalidsig-tparams-notparams-b.check +++ b/test/files/neg/macro-invalidsig-tparams-notparams-b.check @@ -1,4 +1,4 @@ -Macros_Test_2.scala:3: error: wrong number of type parameters for method foo: [T, U, V](c: scala.reflect.macros.Context)(implicit evidence$1: c.WeakTypeTag[T], implicit evidence$2: c.WeakTypeTag[U], implicit V: c.WeakTypeTag[V])c.Expr[Unit] +Macros_Test_2.scala:3: error: macro implementation reference has too few type arguments for method foo: [T, U, V](c: scala.reflect.macros.Context)(implicit evidence$1: c.WeakTypeTag[T], implicit evidence$2: c.WeakTypeTag[U], implicit V: c.WeakTypeTag[V])c.Expr[Unit] def foo[V] = macro Impls.foo ^ one error found diff --git a/test/files/neg/t5689.check b/test/files/neg/t5689.check index 50aaa7dbfe..e497e3bb07 100644 --- a/test/files/neg/t5689.check +++ b/test/files/neg/t5689.check @@ -1,4 +1,4 @@ -t5689.scala:4: error: macro implementation has wrong shape: +t5689.scala:4: error: macro implementation has incompatible shape: required: (c: scala.reflect.macros.Context)(i: c.Expr[Double]): c.Expr[String] found : (c: scala.reflect.macros.Context)(i: c.Expr[Double]): c.Expr[Int] type mismatch for return type: c.Expr[Int] does not conform to c.Expr[String] -- cgit v1.2.3