@@ -20,6 +20,7 @@ import StdNames._
2020import util .Positions ._
2121import Constants ._
2222import ScriptParsers ._
23+ import Decorators ._
2324import scala .annotation .{tailrec , switch }
2425import rewrites .Rewrites .patch
2526
@@ -1101,8 +1102,8 @@ object Parsers {
11011102 * | Expr
11021103 * BlockResult ::= [FunArgMods] FunParams =>' Block
11031104 * | Expr1
1104- * Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
1105- * | [‘inline’] `if' Expr `then' Expr [[semi] else Expr]
1105+ * Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
1106+ * | `if' Expr `then' Expr [[semi] else Expr]
11061107 * | `while' `(' Expr `)' {nl} Expr
11071108 * | `while' Expr `do' Expr
11081109 * | `do' Expr [semi] `while' Expr
@@ -1130,7 +1131,8 @@ object Parsers {
11301131 val start = in.offset
11311132 if (in.token == IMPLICIT || in.token == ERASED ) {
11321133 val imods = modifiers(funArgMods)
1133- implicitClosure(start, location, imods)
1134+ if (in.token == MATCH ) implicitMatch(start, imods)
1135+ else implicitClosure(start, location, imods)
11341136 } else {
11351137 val saved = placeholderParams
11361138 placeholderParams = Nil
@@ -1210,7 +1212,13 @@ object Parsers {
12101212 case FOR =>
12111213 forExpr()
12121214 case _ =>
1213- expr1Rest(postfixExpr(), location)
1215+ if (isIdent(nme.INLINEkw )) {
1216+ val start = in.skipToken()
1217+ val t = postfixExpr()
1218+ accept(MATCH )
1219+ matchExpr(t, start, MatchKind .Inline )
1220+ }
1221+ else expr1Rest(postfixExpr(), location)
12141222 }
12151223
12161224 def expr1Rest (t : Tree , location : Location .Value ): Tree = in.token match {
@@ -1224,7 +1232,7 @@ object Parsers {
12241232 case COLON =>
12251233 ascription(t, location)
12261234 case MATCH =>
1227- matchExpr(t, startOffset(t))
1235+ matchExpr(t, startOffset(t), MatchKind . Regular )
12281236 case _ =>
12291237 t
12301238 }
@@ -1269,12 +1277,34 @@ object Parsers {
12691277 }
12701278
12711279 /** `match' { CaseClauses }
1272- * `match' { ImplicitCaseClauses }
12731280 */
1274- def matchExpr (t : Tree , start : Offset ): Match =
1281+ def matchExpr (t : Tree , start : Offset , kind : MatchKind ): Match =
12751282 atPos(start, in.skipToken()) {
1276- inBraces(Match (t, caseClauses(caseClause)))
1283+ inBraces(Match (t, caseClauses(caseClause), kind))
1284+ }
1285+
1286+ /** `match' { ImplicitCaseClauses }
1287+ */
1288+ def implicitMatch (start : Int , imods : Modifiers ) = {
1289+ def markFirstIllegal (mods : List [Mod ]) = mods match {
1290+ case mod :: _ => syntaxError(em " illegal modifier for implicit match " , mod.pos)
1291+ case _ =>
12771292 }
1293+ imods.mods match {
1294+ case Mod .Implicit () :: mods => markFirstIllegal(mods)
1295+ case mods => markFirstIllegal(mods)
1296+ }
1297+ val result @ Match (t, cases) = matchExpr(EmptyTree , start, MatchKind .Implicit )
1298+ for (CaseDef (pat, _, _) <- cases) {
1299+ def isImplicitPattern (pat : Tree ) = pat match {
1300+ case Typed (pat1, _) => isVarPattern(pat1)
1301+ case pat => isVarPattern(pat)
1302+ }
1303+ if (! isImplicitPattern(pat))
1304+ syntaxError(em " not a legal pattern for an implicit match " , pat.pos)
1305+ }
1306+ result
1307+ }
12781308
12791309 /** `match' { TypeCaseClauses }
12801310 */
@@ -2617,6 +2647,8 @@ object Parsers {
26172647 var imods = modifiers(funArgMods)
26182648 if (isBindingIntro && ! isIdent(nme.INLINEkw ))
26192649 stats += implicitClosure(start, Location .InBlock , imods)
2650+ else if (in.token == MATCH )
2651+ stats += implicitMatch(start, imods)
26202652 else
26212653 stats +++= localDef(start, imods)
26222654 } else {
0 commit comments