@@ -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
@@ -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,21 @@ object Parsers {
1207
1209
case FOR =>
1208
1210
forExpr()
1209
1211
case _ =>
1210
- expr1Rest(postfixExpr(), location)
1212
+ if (isIdent(nme.inline) && ! in.inModifierPosition() && in.lookaheadIn(canStartExpressionTokens)) {
1213
+ val start = in.skipToken()
1214
+ in.token match {
1215
+ case IF =>
1216
+ ifExpr(start, InlineIf )
1217
+ case _ =>
1218
+ val t = postfixExpr()
1219
+ if (in.token == MATCH ) matchExpr(t, start, InlineMatch )
1220
+ else {
1221
+ syntaxErrorOrIncomplete(i " `match` or `if` expected but ${in.token} found " )
1222
+ t
1223
+ }
1224
+ }
1225
+ }
1226
+ else expr1Rest(postfixExpr(), location)
1211
1227
}
1212
1228
1213
1229
def expr1Rest (t : Tree , location : Location .Value ): Tree = in.token match {
@@ -1221,7 +1237,7 @@ object Parsers {
1221
1237
case COLON =>
1222
1238
ascription(t, location)
1223
1239
case MATCH =>
1224
- matchExpr(t, startOffset(t))
1240
+ matchExpr(t, startOffset(t), Match )
1225
1241
case _ =>
1226
1242
t
1227
1243
}
@@ -1266,13 +1282,36 @@ object Parsers {
1266
1282
}
1267
1283
1268
1284
/** `match' { CaseClauses }
1269
- * `match' { ImplicitCaseClauses }
1270
1285
*/
1271
- def matchExpr (t : Tree , start : Offset ) : Match =
1286
+ def matchExpr (t : Tree , start : Offset , mkMatch : ( Tree , List [ CaseDef ]) => Match ) =
1272
1287
atPos(start, in.skipToken()) {
1273
- inBraces(Match (t, caseClauses(caseClause)))
1288
+ inBraces(mkMatch (t, caseClauses(caseClause)))
1274
1289
}
1275
1290
1291
+ /** `match' { ImplicitCaseClauses }
1292
+ */
1293
+ def implicitMatch (start : Int , imods : Modifiers ) = {
1294
+ def markFirstIllegal (mods : List [Mod ]) = mods match {
1295
+ case mod :: _ => syntaxError(em " illegal modifier for implicit match " , mod.pos)
1296
+ case _ =>
1297
+ }
1298
+ imods.mods match {
1299
+ case Mod .Implicit () :: mods => markFirstIllegal(mods)
1300
+ case mods => markFirstIllegal(mods)
1301
+ }
1302
+ val result @ Match (t, cases) =
1303
+ matchExpr(EmptyTree , start, InlineMatch )
1304
+ for (CaseDef (pat, _, _) <- cases) {
1305
+ def isImplicitPattern (pat : Tree ) = pat match {
1306
+ case Typed (pat1, _) => isVarPattern(pat1)
1307
+ case pat => isVarPattern(pat)
1308
+ }
1309
+ if (! isImplicitPattern(pat))
1310
+ syntaxError(em " not a legal pattern for an implicit match " , pat.pos)
1311
+ }
1312
+ result
1313
+ }
1314
+
1276
1315
/** `match' { TypeCaseClauses }
1277
1316
*/
1278
1317
def matchType (bound : Tree , t : Tree ): MatchTypeTree =
@@ -2620,6 +2659,8 @@ object Parsers {
2620
2659
var imods = modifiers(funArgMods)
2621
2660
if (isBindingIntro)
2622
2661
stats += implicitClosure(start, Location .InBlock , imods)
2662
+ else if (in.token == MATCH )
2663
+ stats += implicitMatch(start, imods)
2623
2664
else
2624
2665
stats +++= localDef(start, imods)
2625
2666
} else {
0 commit comments