@@ -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
@@ -1101,8 +1102,8 @@ object Parsers {
1101
1102
* | Expr
1102
1103
* BlockResult ::= [FunArgMods] FunParams =>' Block
1103
1104
* | 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]
1106
1107
* | `while' `(' Expr `)' {nl} Expr
1107
1108
* | `while' Expr `do' Expr
1108
1109
* | `do' Expr [semi] `while' Expr
@@ -1130,7 +1131,8 @@ object Parsers {
1130
1131
val start = in.offset
1131
1132
if (in.token == IMPLICIT || in.token == ERASED ) {
1132
1133
val imods = modifiers(funArgMods)
1133
- implicitClosure(start, location, imods)
1134
+ if (in.token == MATCH ) implicitMatch(start, imods)
1135
+ else implicitClosure(start, location, imods)
1134
1136
} else {
1135
1137
val saved = placeholderParams
1136
1138
placeholderParams = Nil
@@ -1210,7 +1212,13 @@ object Parsers {
1210
1212
case FOR =>
1211
1213
forExpr()
1212
1214
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)
1214
1222
}
1215
1223
1216
1224
def expr1Rest (t : Tree , location : Location .Value ): Tree = in.token match {
@@ -1224,7 +1232,7 @@ object Parsers {
1224
1232
case COLON =>
1225
1233
ascription(t, location)
1226
1234
case MATCH =>
1227
- matchExpr(t, startOffset(t))
1235
+ matchExpr(t, startOffset(t), MatchKind . Regular )
1228
1236
case _ =>
1229
1237
t
1230
1238
}
@@ -1269,12 +1277,34 @@ object Parsers {
1269
1277
}
1270
1278
1271
1279
/** `match' { CaseClauses }
1272
- * `match' { ImplicitCaseClauses }
1273
1280
*/
1274
- def matchExpr (t : Tree , start : Offset ): Match =
1281
+ def matchExpr (t : Tree , start : Offset , kind : MatchKind ): Match =
1275
1282
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 _ =>
1277
1292
}
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
+ }
1278
1308
1279
1309
/** `match' { TypeCaseClauses }
1280
1310
*/
@@ -2617,6 +2647,8 @@ object Parsers {
2617
2647
var imods = modifiers(funArgMods)
2618
2648
if (isBindingIntro && ! isIdent(nme.INLINEkw ))
2619
2649
stats += implicitClosure(start, Location .InBlock , imods)
2650
+ else if (in.token == MATCH )
2651
+ stats += implicitMatch(start, imods)
2620
2652
else
2621
2653
stats +++= localDef(start, imods)
2622
2654
} else {
0 commit comments