Skip to content

Commit 5626c74

Browse files
committed
[nomaster] macro errors now always have positions
Back then when I implemented macros for inclusion in trunk (Spring 2012), partest didn't support the _1, _2, ... convention for neg tests, so I had to use toolboxes to test macro-generated exceptions. Unfortunately toolboxes aren't very good with positions (mostly because their inputs are almost always constructed without corresponding sources) so I didn't notice that errors signalizing about macro-generated exceptions actually don't carry positions with them because of a typo. This patch fixes the oversight, but it doesn't need to be ported to master, because over there everything's already fixed by one of the backports from macro paradise.
1 parent ed5c1ab commit 5626c74

File tree

7 files changed

+36
-1
lines changed

7 files changed

+36
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ trait ContextErrors {
697697
def msgForLog = if (msg != null && (msg contains "exception during macro expansion")) msg.split(EOL).drop(1).headOption.getOrElse("?") else msg
698698
macroLogLite("macro expansion has failed: %s".format(msgForLog))
699699
val errorPos = if (pos != NoPosition) pos else (if (expandee.pos != NoPosition) expandee.pos else enclosingMacroPosition)
700-
if (msg != null) context.error(pos, msg) // issueTypeError(PosAndMsgTypeError(..)) won't work => swallows positions
700+
if (msg != null) context.error(errorPos, msg) // issueTypeError(PosAndMsgTypeError(..)) won't work => swallows positions
701701
setError(expandee)
702702
throw MacroExpansionException
703703
}

test/files/neg/macro-abort.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Test_2.scala:2: error: aborted
2+
Macros.abort
3+
^
4+
one error found
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.language.experimental.macros
2+
import scala.reflect.macros.Context
3+
4+
object Macros {
5+
def impl(c: Context) = {
6+
c.abort(c.enclosingPosition, "aborted")
7+
}
8+
def abort = macro impl
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test extends App {
2+
Macros.abort
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Test_2.scala:2: error: exception during macro expansion:
2+
java.lang.Exception
3+
at Macros$.impl(Macros_1.scala:6)
4+
5+
Macros.exception
6+
^
7+
one error found
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.language.experimental.macros
2+
import scala.reflect.macros.Context
3+
4+
object Macros {
5+
def impl(c: Context) = {
6+
throw new Exception()
7+
}
8+
def exception = macro impl
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test extends App {
2+
Macros.exception
3+
}

0 commit comments

Comments
 (0)