Skip to content

Commit 761d023

Browse files
committed
Parse macro ??? as ??? to compile the standard library
This gets us closer to the goal of compiling the standard library without any patch.
1 parent b539b34 commit 761d023

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
@@ -133,6 +133,9 @@ object Parsers {
133133
*/
134134
def syntaxError(msg: => Message, span: Span): Unit =
135135
ctx.error(msg, source.atSpan(span))
136+
137+
def unimplementedExpr(implicit ctx: Context): Select =
138+
Select(Select(rootDot(nme.scala_), nme.Predef), nme.???)
136139
}
137140

138141
trait OutlineParserCommon extends ParserCommon {
@@ -1445,6 +1448,17 @@ object Parsers {
14451448
case NEW =>
14461449
canApply = false
14471450
newExpr()
1451+
case MACRO =>
1452+
val start = in.skipToken()
1453+
val call = ident()
1454+
// The standard library uses "macro ???" to denote "fast track" macros
1455+
// hardcoded in the compiler, don't issue an error for those macros
1456+
// since we want to be able to compile the standard library.
1457+
if (call `ne` nme.???)
1458+
syntaxError(
1459+
"Scala 2 macros are not supported, see http://dotty.epfl.ch/docs/reference/dropped-features/macros.html",
1460+
start)
1461+
unimplementedExpr
14481462
case _ =>
14491463
if (isLiteral) literal()
14501464
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")
@@ -200,7 +201,7 @@ object Tokens extends TokensCommon {
200201
/** XML mode */
201202
final val XMLSTART = 96; enter(XMLSTART, "$XMLSTART$<") // TODO: deprecate
202203

203-
final val alphaKeywords: TokenSet = tokenRange(IF, GIVEN)
204+
final val alphaKeywords: TokenSet = tokenRange(IF, MACRO)
204205
final val symbolicKeywords: TokenSet = tokenRange(USCORE, VIEWBOUND)
205206
final val symbolicTokens: TokenSet = tokenRange(COMMA, VIEWBOUND)
206207
final val keywords: TokenSet = alphaKeywords | symbolicKeywords

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)