Skip to content

Commit ffb250d

Browse files
authored
Merge pull request #6550 from dotty-staging/fix-scala2-maco
Improve Scala 2 macro error handling
2 parents 6e9200a + 1ac830a commit ffb250d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,8 +2809,10 @@ class Typer extends Namer
28092809
}
28102810
else if (tree.symbol.isScala2Macro) {
28112811
if (ctx.settings.XignoreScala2Macros.value) {
2812-
ctx.warning("Scala 2 macro cannot be used in Dotty, this call will crash at runtime. See http://dotty.epfl.ch/docs/reference/dropped-features/macros.html", tree.sourcePos)
2813-
Throw(New(defn.MatchErrorType, Literal(Constant(s"Reached unexpanded Scala 2 macro call to ${tree.symbol.showFullName} compiled with -Xignore-scala2-macros.")) :: Nil)).withSpan(tree.span)
2812+
ctx.warning("Scala 2 macro cannot be used in Dotty, this call will crash at runtime. See http://dotty.epfl.ch/docs/reference/dropped-features/macros.html", tree.sourcePos.startPos)
2813+
Throw(New(defn.MatchErrorType, Literal(Constant(s"Reached unexpanded Scala 2 macro call to ${tree.symbol.showFullName} compiled with -Xignore-scala2-macros.")) :: Nil))
2814+
.withType(tree.tpe)
2815+
.withSpan(tree.span)
28142816
} else if (tree.symbol eq defn.StringContext_f) {
28152817
// As scala.StringContext.f is defined in the standard library which
28162818
// we currently do not bootstrap we cannot implement the macro the library.
@@ -2821,7 +2823,9 @@ class Typer extends Namer
28212823
val newCall = ref(defn.InternalStringContextMacroModule_f).appliedTo(sc).appliedToArgs(args)
28222824
readaptSimplified(Inliner.inlineCall(newCall))
28232825
} else {
2824-
ctx.error("Scala 2 macro cannot be used in Dotty. See http://dotty.epfl.ch/docs/reference/dropped-features/macros.html", tree.sourcePos)
2826+
ctx.error(
2827+
"""Scala 2 macro cannot be used in Dotty. See http://dotty.epfl.ch/docs/reference/dropped-features/macros.html\n"
2828+
|To turn this error into a warning, pass -Xignore-scala2-macros to the compiler""".stripMargin, tree.sourcePos.startPos)
28252829
tree
28262830
}
28272831
}

0 commit comments

Comments
 (0)