@@ -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
@@ -1098,8 +1099,8 @@ object Parsers {
10981099 * | Expr
10991100 * BlockResult ::= [FunArgMods] FunParams =>' Block
11001101 * | Expr1
1101- * Expr1 ::= [‘inline’] `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
1102- * | [‘inline’] `if' Expr `then' Expr [[semi] else Expr]
1102+ * Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr]
1103+ * | `if' Expr `then' Expr [[semi] else Expr]
11031104 * | `while' `(' Expr `)' {nl} Expr
11041105 * | `while' Expr `do' Expr
11051106 * | `do' Expr [semi] `while' Expr
@@ -1127,7 +1128,8 @@ object Parsers {
11271128 val start = in.offset
11281129 if (in.token == IMPLICIT || in.token == ERASED ) {
11291130 val imods = modifiers(funArgMods)
1130- implicitClosure(start, location, imods)
1131+ if (in.token == MATCH ) implicitMatch(start, imods)
1132+ else implicitClosure(start, location, imods)
11311133 } else {
11321134 val saved = placeholderParams
11331135 placeholderParams = Nil
@@ -1207,7 +1209,13 @@ object Parsers {
12071209 case FOR =>
12081210 forExpr()
12091211 case _ =>
1210- expr1Rest(postfixExpr(), location)
1212+ if (isIdent(nme.INLINEkw )) {
1213+ val start = in.skipToken()
1214+ val t = postfixExpr()
1215+ accept(MATCH )
1216+ matchExpr(t, start, MatchKind .Inline )
1217+ }
1218+ else expr1Rest(postfixExpr(), location)
12111219 }
12121220
12131221 def expr1Rest (t : Tree , location : Location .Value ): Tree = in.token match {
@@ -1221,7 +1229,7 @@ object Parsers {
12211229 case COLON =>
12221230 ascription(t, location)
12231231 case MATCH =>
1224- matchExpr(t, startOffset(t))
1232+ matchExpr(t, startOffset(t), MatchKind . Regular )
12251233 case _ =>
12261234 t
12271235 }
@@ -1266,12 +1274,34 @@ object Parsers {
12661274 }
12671275
12681276 /** `match' { CaseClauses }
1269- * `match' { ImplicitCaseClauses }
12701277 */
1271- def matchExpr (t : Tree , start : Offset ): Match =
1278+ def matchExpr (t : Tree , start : Offset , kind : MatchKind ): Match =
12721279 atPos(start, in.skipToken()) {
1273- inBraces(Match (t, caseClauses(caseClause)))
1280+ inBraces(Match (t, caseClauses(caseClause), kind))
1281+ }
1282+
1283+ /** `match' { ImplicitCaseClauses }
1284+ */
1285+ def implicitMatch (start : Int , imods : Modifiers ) = {
1286+ def markFirstIllegal (mods : List [Mod ]) = mods match {
1287+ case mod :: _ => syntaxError(em " illegal modifier for implicit match " , mod.pos)
1288+ case _ =>
12741289 }
1290+ imods.mods match {
1291+ case Mod .Implicit () :: mods => markFirstIllegal(mods)
1292+ case mods => markFirstIllegal(mods)
1293+ }
1294+ val result @ Match (t, cases) = matchExpr(EmptyTree , start, MatchKind .Implicit )
1295+ for (CaseDef (pat, _, _) <- cases) {
1296+ def isImplicitPattern (pat : Tree ) = pat match {
1297+ case Typed (pat1, _) => isVarPattern(pat1)
1298+ case pat => isVarPattern(pat)
1299+ }
1300+ if (! isImplicitPattern(pat))
1301+ syntaxError(em " not a legal pattern for an implicit match " , pat.pos)
1302+ }
1303+ result
1304+ }
12751305
12761306 /** `match' { TypeCaseClauses }
12771307 */
@@ -2620,6 +2650,8 @@ object Parsers {
26202650 var imods = modifiers(funArgMods)
26212651 if (isBindingIntro)
26222652 stats += implicitClosure(start, Location .InBlock , imods)
2653+ else if (in.token == MATCH )
2654+ stats += implicitMatch(start, imods)
26232655 else
26242656 stats +++= localDef(start, imods)
26252657 } else {
0 commit comments