Skip to content

Commit

Permalink
[nomaster] better error messages for various macro definition errors
Browse files Browse the repository at this point in the history
backport of 1d3ec4e
  • Loading branch information
xeno-by committed Dec 6, 2013
1 parent 7e996c1 commit 3faa2ee
Show file tree
Hide file tree
Showing 19 changed files with 25 additions and 27 deletions.
10 changes: 7 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1328,15 +1328,19 @@ 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")

// Phase III: check compatibility between the macro def and its macro impl
// 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")

Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidimpl-f.check
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidimpl-g.check
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidret-nontree.check
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidret-nonuniversetree.check
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
5 changes: 1 addition & 4 deletions test/files/neg/macro-invalidsig-context-bounds.check
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidsig-ctx-badargc.check
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidsig-ctx-badtype.check
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidsig-ctx-badvarargs.check
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidsig-ctx-noctx.check
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 1 addition & 4 deletions test/files/neg/macro-invalidsig-implicit-params.check
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidsig-params-badargc.check
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidsig-params-badtype.check
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidsig-params-badvarargs.check
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidsig-params-namemismatch.check
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidsig-tparams-badtype.check
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidsig-tparams-notparams-a.check
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/files/neg/macro-invalidsig-tparams-notparams-b.check
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/files/neg/t5689.check
Original file line number Diff line number Diff line change
@@ -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]
Expand Down

0 comments on commit 3faa2ee

Please sign in to comment.