Skip to content

Commit 789269d

Browse files
authored
Merge pull request #5972 from dotty-staging/add/macro-kw
Parse `macro ???` as `???` to compile the standard library
2 parents ac84182 + 761d023 commit 789269d

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ object JavaParsers {
104104
def arrayOf(tpt: Tree): AppliedTypeTree =
105105
AppliedTypeTree(Ident(nme.Array.toTypeName), List(tpt))
106106

107-
def unimplementedExpr(implicit ctx: Context): Select =
108-
Select(Select(rootDot(nme.scala_), nme.Predef), nme.???)
109-
110107
def makeTemplate(parents: List[Tree], stats: List[Tree], tparams: List[TypeDef], needsDummyConstr: Boolean): Template = {
111108
def pullOutFirstConstr(stats: List[Tree]): (Tree, List[Tree]) = stats match {
112109
case (meth: DefDef) :: rest if meth.name == nme.CONSTRUCTOR => (meth, rest)

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ object Parsers {
141141
*/
142142
def syntaxError(msg: => Message, span: Span): Unit =
143143
ctx.error(msg, source.atSpan(span))
144+
145+
def unimplementedExpr(implicit ctx: Context): Select =
146+
Select(Select(rootDot(nme.scala_), nme.Predef), nme.???)
144147
}
145148

146149
trait OutlineParserCommon extends ParserCommon {
@@ -1520,6 +1523,17 @@ object Parsers {
15201523
case NEW =>
15211524
canApply = false
15221525
newExpr()
1526+
case MACRO =>
1527+
val start = in.skipToken()
1528+
val call = ident()
1529+
// The standard library uses "macro ???" to denote "fast track" macros
1530+
// hardcoded in the compiler, don't issue an error for those macros
1531+
// since we want to be able to compile the standard library.
1532+
if (call `ne` nme.???)
1533+
syntaxError(
1534+
"Scala 2 macros are not supported, see http://dotty.epfl.ch/docs/reference/dropped-features/macros.html",
1535+
start)
1536+
unimplementedExpr
15231537
case _ =>
15241538
if (isLiteral) literal()
15251539
else {

compiler/src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ object Tokens extends TokensCommon {
180180
final val ERASED = 63; enter(ERASED, "erased")
181181
final val IMPLIED = 64; enter(IMPLIED, "implied")
182182
final val GIVEN = 65; enter(GIVEN, "given")
183+
final val MACRO = 66; enter(MACRO, "macro") // TODO: remove
183184

184185
/** special symbols */
185186
final val NEWLINE = 78; enter(NEWLINE, "end of statement", "new line")
@@ -198,7 +199,7 @@ object Tokens extends TokensCommon {
198199
/** XML mode */
199200
final val XMLSTART = 96; enter(XMLSTART, "$XMLSTART$<") // TODO: deprecate
200201

201-
final val alphaKeywords: TokenSet = tokenRange(IF, GIVEN)
202+
final val alphaKeywords: TokenSet = tokenRange(IF, MACRO)
202203
final val symbolicKeywords: TokenSet = tokenRange(USCORE, VIEWBOUND)
203204
final val keywords: TokenSet = alphaKeywords | symbolicKeywords
204205

compiler/test/dotc/pos-decompilation.blacklist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ implicit-match.scala
2121
implicit-match-nested.scala
2222
implicit-match-and-inline-match.scala
2323

24+
# Need to add backquotes around "macro" since it's a keyword
25+
macro-deprecate-dont-touch-backquotedidents.scala

tests/neg/macro.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class A {
2+
def bla = ???
3+
def foo: Int = macro bla // error
4+
}

tests/pos/macro.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class A {
2+
def foo: Int = macro ???
3+
}

0 commit comments

Comments
 (0)