diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-08-12 01:50:10 -0700 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-08-12 01:50:10 -0700 |
commit | fb3725c9427b91844155112e116e5f12a87e9e6a (patch) | |
tree | 582a15327326ccbfab534cf26c2598687e2eabad | |
parent | ed5c1abbfca18a880c79048cc7e9578ae932101d (diff) | |
parent | 5626c7403e44380c6e3610cae8f68f3d2b52eb70 (diff) | |
download | scala-fb3725c9427b91844155112e116e5f12a87e9e6a.tar.gz scala-fb3725c9427b91844155112e116e5f12a87e9e6a.tar.bz2 scala-fb3725c9427b91844155112e116e5f12a87e9e6a.zip |
Merge pull request #2818 from xeno-by/topic/macro-expansion-error-pos
[nomaster] macro errors now always have positions
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala | 2 | ||||
-rw-r--r-- | test/files/neg/macro-abort.check | 4 | ||||
-rw-r--r-- | test/files/neg/macro-abort/Macros_1.scala | 9 | ||||
-rw-r--r-- | test/files/neg/macro-abort/Test_2.scala | 3 | ||||
-rw-r--r-- | test/files/neg/macro-exception.check | 7 | ||||
-rw-r--r-- | test/files/neg/macro-exception/Macros_1.scala | 9 | ||||
-rw-r--r-- | test/files/neg/macro-exception/Test_2.scala | 3 |
7 files changed, 36 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index b9cff5b2d3..5d6d094b44 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -697,7 +697,7 @@ trait ContextErrors { def msgForLog = if (msg != null && (msg contains "exception during macro expansion")) msg.split(EOL).drop(1).headOption.getOrElse("?") else msg macroLogLite("macro expansion has failed: %s".format(msgForLog)) val errorPos = if (pos != NoPosition) pos else (if (expandee.pos != NoPosition) expandee.pos else enclosingMacroPosition) - if (msg != null) context.error(pos, msg) // issueTypeError(PosAndMsgTypeError(..)) won't work => swallows positions + if (msg != null) context.error(errorPos, msg) // issueTypeError(PosAndMsgTypeError(..)) won't work => swallows positions setError(expandee) throw MacroExpansionException } diff --git a/test/files/neg/macro-abort.check b/test/files/neg/macro-abort.check new file mode 100644 index 0000000000..1e58add533 --- /dev/null +++ b/test/files/neg/macro-abort.check @@ -0,0 +1,4 @@ +Test_2.scala:2: error: aborted + Macros.abort + ^ +one error found diff --git a/test/files/neg/macro-abort/Macros_1.scala b/test/files/neg/macro-abort/Macros_1.scala new file mode 100644 index 0000000000..676c112098 --- /dev/null +++ b/test/files/neg/macro-abort/Macros_1.scala @@ -0,0 +1,9 @@ +import scala.language.experimental.macros +import scala.reflect.macros.Context + +object Macros { + def impl(c: Context) = { + c.abort(c.enclosingPosition, "aborted") + } + def abort = macro impl +}
\ No newline at end of file diff --git a/test/files/neg/macro-abort/Test_2.scala b/test/files/neg/macro-abort/Test_2.scala new file mode 100644 index 0000000000..1d0a7a25dc --- /dev/null +++ b/test/files/neg/macro-abort/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + Macros.abort +}
\ No newline at end of file diff --git a/test/files/neg/macro-exception.check b/test/files/neg/macro-exception.check new file mode 100644 index 0000000000..cee8b32ebd --- /dev/null +++ b/test/files/neg/macro-exception.check @@ -0,0 +1,7 @@ +Test_2.scala:2: error: exception during macro expansion: +java.lang.Exception + at Macros$.impl(Macros_1.scala:6) + + Macros.exception + ^ +one error found diff --git a/test/files/neg/macro-exception/Macros_1.scala b/test/files/neg/macro-exception/Macros_1.scala new file mode 100644 index 0000000000..60e4020aec --- /dev/null +++ b/test/files/neg/macro-exception/Macros_1.scala @@ -0,0 +1,9 @@ +import scala.language.experimental.macros +import scala.reflect.macros.Context + +object Macros { + def impl(c: Context) = { + throw new Exception() + } + def exception = macro impl +}
\ No newline at end of file diff --git a/test/files/neg/macro-exception/Test_2.scala b/test/files/neg/macro-exception/Test_2.scala new file mode 100644 index 0000000000..d82b21f2b2 --- /dev/null +++ b/test/files/neg/macro-exception/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + Macros.exception +}
\ No newline at end of file |