diff options
-rw-r--r-- | src/compiler/scala/reflect/macros/compiler/Errors.scala | 21 | ||||
-rw-r--r-- | test/files/neg/t6123-explaintypes-macros.check | 9 | ||||
-rw-r--r-- | test/files/neg/t6123-explaintypes-macros/BadMac_2.flags (renamed from test/files/pos/t6123-explaintypes-macros.flags) | 0 | ||||
-rw-r--r-- | test/files/neg/t6123-explaintypes-macros/BadMac_2.scala | 8 | ||||
-rw-r--r-- | test/files/neg/t6123-explaintypes-macros/Macros.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t6123-explaintypes-macros/Macros.scala (renamed from test/files/pos/t6123-explaintypes-macros.scala) | 3 |
6 files changed, 33 insertions, 9 deletions
diff --git a/src/compiler/scala/reflect/macros/compiler/Errors.scala b/src/compiler/scala/reflect/macros/compiler/Errors.scala index a60a2c2306..6ec111cf7c 100644 --- a/src/compiler/scala/reflect/macros/compiler/Errors.scala +++ b/src/compiler/scala/reflect/macros/compiler/Errors.scala @@ -53,7 +53,7 @@ trait Errors extends Traces { // not exactly an error generator, but very related // and I dearly wanted to push it away from Macros.scala private def checkConforms(slot: String, rtpe: Type, atpe: Type) = { - val verbose = macroDebugVerbose || settings.explaintypes.value + val verbose = macroDebugVerbose def check(rtpe: Type, atpe: Type): Boolean = { def success() = { if (verbose) println(rtpe + " <: " + atpe + "?" + EOL + "true"); true } @@ -70,9 +70,12 @@ trait Errors extends Traces { if (verbose) withTypesExplained(check(rtpe, atpe)) else check(rtpe, atpe) if (!ok) { - if (!macroDebugVerbose) - explainTypes(rtpe, atpe) - compatibilityError("type mismatch for %s: %s does not conform to %s".format(slot, abbreviateCoreAliases(rtpe.toString), abbreviateCoreAliases(atpe.toString))) + if (!verbose) explainTypes(rtpe, atpe) + val msg = { + val ss = Seq(rtpe, atpe) map (this abbreviateCoreAliases _.toString) + s"type mismatch for $slot: ${ss(0)} does not conform to ${ss(1)}" + } + compatibilityError(msg) } } @@ -106,8 +109,8 @@ trait Errors extends Traces { def MacroImplTargMismatchError(atargs: List[Type], atparams: List[Symbol]) = compatibilityError(NotWithinBoundsErrorMessage("", atargs, atparams, macroDebugVerbose || settings.explaintypes.value)) - def MacroImplTparamInstantiationError(atparams: List[Symbol], ex: NoInstance) = - compatibilityError( - "type parameters "+(atparams map (_.defString) mkString ", ")+" cannot be instantiated\n"+ - ex.getMessage) -}
\ No newline at end of file + def MacroImplTparamInstantiationError(atparams: List[Symbol], e: NoInstance) = { + val badps = atparams map (_.defString) mkString ", " + compatibilityError(f"type parameters $badps cannot be instantiated%n${e.getMessage}") + } +} diff --git a/test/files/neg/t6123-explaintypes-macros.check b/test/files/neg/t6123-explaintypes-macros.check new file mode 100644 index 0000000000..ebcb8069d5 --- /dev/null +++ b/test/files/neg/t6123-explaintypes-macros.check @@ -0,0 +1,9 @@ +c.universe.Expr[Any]* <: c.universe.Expr[String]*? +false +BadMac_2.scala:6: error: macro implementation has wrong shape: + required: (c: scala.reflect.macros.Context)(format: c.Expr[String], params: c.Expr[Any]*): c.Expr[Unit] + found : (c: scala.reflect.macros.Context)(format: c.Expr[String], params: c.Expr[String]*): c.Expr[Unit] +type mismatch for parameter params: c.Expr[Any]* does not conform to c.Expr[String]* + def printf(format: String, params: Any*): Unit = macro printf_impl + ^ +one error found diff --git a/test/files/pos/t6123-explaintypes-macros.flags b/test/files/neg/t6123-explaintypes-macros/BadMac_2.flags index b36707c7cf..b36707c7cf 100644 --- a/test/files/pos/t6123-explaintypes-macros.flags +++ b/test/files/neg/t6123-explaintypes-macros/BadMac_2.flags diff --git a/test/files/neg/t6123-explaintypes-macros/BadMac_2.scala b/test/files/neg/t6123-explaintypes-macros/BadMac_2.scala new file mode 100644 index 0000000000..38b8e24444 --- /dev/null +++ b/test/files/neg/t6123-explaintypes-macros/BadMac_2.scala @@ -0,0 +1,8 @@ +import scala.language.experimental.macros +import scala.reflect.macros.Context + +// explain some macro types to me +object BadMac { + def printf(format: String, params: Any*): Unit = macro printf_impl + def printf_impl(c: Context)(format: c.Expr[String], params: c.Expr[String]*): c.Expr[Unit] = ??? +} diff --git a/test/files/neg/t6123-explaintypes-macros/Macros.flags b/test/files/neg/t6123-explaintypes-macros/Macros.flags new file mode 100644 index 0000000000..b36707c7cf --- /dev/null +++ b/test/files/neg/t6123-explaintypes-macros/Macros.flags @@ -0,0 +1 @@ +-explaintypes diff --git a/test/files/pos/t6123-explaintypes-macros.scala b/test/files/neg/t6123-explaintypes-macros/Macros.scala index e650ad2038..a12c277c86 100644 --- a/test/files/pos/t6123-explaintypes-macros.scala +++ b/test/files/neg/t6123-explaintypes-macros/Macros.scala @@ -5,3 +5,6 @@ object Macros { def printf(format: String, params: Any*): Unit = macro printf_impl def printf_impl(c: Context)(format: c.Expr[String], params: c.Expr[Any]*): c.Expr[Unit] = ??? } + +// something trivial to run +object Test extends App |