@@ -20,6 +20,7 @@ import StdNames._
20
20
import util .Positions ._
21
21
import Constants ._
22
22
import ScriptParsers ._
23
+ import Decorators ._
23
24
import scala .annotation .{tailrec , switch }
24
25
import rewrites .Rewrites .patch
25
26
@@ -1098,8 +1099,8 @@ object Parsers {
1098
1099
* | Expr
1099
1100
* BlockResult ::= [FunArgMods] FunParams =>' Block
1100
1101
* | 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]
1103
1104
* | `while' `(' Expr `)' {nl} Expr
1104
1105
* | `while' Expr `do' Expr
1105
1106
* | `do' Expr [semi] `while' Expr
@@ -1127,7 +1128,8 @@ object Parsers {
1127
1128
val start = in.offset
1128
1129
if (in.token == IMPLICIT || in.token == ERASED ) {
1129
1130
val imods = modifiers(funArgMods)
1130
- implicitClosure(start, location, imods)
1131
+ if (in.token == MATCH ) implicitMatch(start, imods)
1132
+ else implicitClosure(start, location, imods)
1131
1133
} else {
1132
1134
val saved = placeholderParams
1133
1135
placeholderParams = Nil
@@ -1207,7 +1209,13 @@ object Parsers {
1207
1209
case FOR =>
1208
1210
forExpr()
1209
1211
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)
1211
1219
}
1212
1220
1213
1221
def expr1Rest (t : Tree , location : Location .Value ): Tree = in.token match {
@@ -1221,7 +1229,7 @@ object Parsers {
1221
1229
case COLON =>
1222
1230
ascription(t, location)
1223
1231
case MATCH =>
1224
- matchExpr(t, startOffset(t))
1232
+ matchExpr(t, startOffset(t), MatchKind . Regular )
1225
1233
case _ =>
1226
1234
t
1227
1235
}
@@ -1266,12 +1274,34 @@ object Parsers {
1266
1274
}
1267
1275
1268
1276
/** `match' { CaseClauses }
1269
- * `match' { ImplicitCaseClauses }
1270
1277
*/
1271
- def matchExpr (t : Tree , start : Offset ): Match =
1278
+ def matchExpr (t : Tree , start : Offset , kind : MatchKind ): Match =
1272
1279
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 _ =>
1274
1289
}
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
+ }
1275
1305
1276
1306
/** `match' { TypeCaseClauses }
1277
1307
*/
@@ -2620,6 +2650,8 @@ object Parsers {
2620
2650
var imods = modifiers(funArgMods)
2621
2651
if (isBindingIntro)
2622
2652
stats += implicitClosure(start, Location .InBlock , imods)
2653
+ else if (in.token == MATCH )
2654
+ stats += implicitMatch(start, imods)
2623
2655
else
2624
2656
stats +++= localDef(start, imods)
2625
2657
} else {
0 commit comments