@@ -1360,8 +1360,8 @@ object Parsers {
1360
1360
*/
1361
1361
def typ (): Tree = {
1362
1362
val start = in.offset
1363
- var imods = Modifiers ()
1364
- def functionRest ( params : List [ Tree ]) : Tree =
1363
+ def functionRest ( params : List [ Tree ], mods : Modifiers ) : Tree =
1364
+ var imods = mods
1365
1365
atSpan(start, in.offset) {
1366
1366
if in.token == TLARROW then
1367
1367
if ! imods.flags.isEmpty || params.isEmpty then
@@ -1389,61 +1389,11 @@ object Parsers {
1389
1389
Function (params, t)
1390
1390
}
1391
1391
}
1392
- def funArgTypesRest (first : Tree , following : () => Tree ) = {
1393
- val buf = new ListBuffer [Tree ] += first
1394
- while (in.token == COMMA ) {
1395
- in.nextToken()
1396
- buf += following()
1397
- }
1398
- buf.toList
1399
- }
1400
- var isValParamList = false
1401
1392
1402
1393
val t =
1403
- if (in.token == LPAREN ) {
1404
- in.nextToken()
1405
- if (in.token == RPAREN ) {
1406
- in.nextToken()
1407
- functionRest(Nil )
1408
- }
1409
- else {
1410
- openParens.change(LPAREN , 1 )
1411
- imods = modifiers(funTypeArgMods)
1412
- val paramStart = in.offset
1413
- val ts = funArgType() match {
1414
- case Ident (name) if name != tpnme.WILDCARD && in.token == COLON =>
1415
- isValParamList = true
1416
- funArgTypesRest(
1417
- typedFunParam(paramStart, name.toTermName, imods),
1418
- () => typedFunParam(in.offset, ident(), imods))
1419
- case t =>
1420
- funArgTypesRest(t, funArgType)
1421
- }
1422
- openParens.change(LPAREN , - 1 )
1423
- accept(RPAREN )
1424
- if isValParamList || in.token == ARROW || in.token == CTXARROW then
1425
- functionRest(ts)
1426
- else {
1427
- val ts1 =
1428
- for (t <- ts) yield
1429
- t match {
1430
- case t@ ByNameTypeTree (t1) =>
1431
- syntaxError(ByNameParameterNotSupported (t), t.span)
1432
- t1
1433
- case _ =>
1434
- t
1435
- }
1436
- val tuple = atSpan(start) { makeTupleOrParens(ts1) }
1437
- infixTypeRest(
1438
- refinedTypeRest(
1439
- withTypeRest(
1440
- annotTypeRest(
1441
- simpleTypeRest(tuple)))))
1442
- }
1443
- }
1444
- }
1394
+ if in.token == LPAREN then
1395
+ typAfterParens(functionRest)
1445
1396
else if (in.token == LBRACKET ) {
1446
- val start = in.offset
1447
1397
val tparams = typeParamClause(ParamOwner .TypeParam )
1448
1398
if (in.token == TLARROW )
1449
1399
atSpan(start, in.skipToken())(LambdaTypeTree (tparams, toplevelTyp()))
@@ -1465,16 +1415,64 @@ object Parsers {
1465
1415
else infixType()
1466
1416
1467
1417
in.token match {
1468
- case ARROW | CTXARROW => functionRest(t :: Nil )
1418
+ case ARROW | CTXARROW => functionRest(t :: Nil , Modifiers () )
1469
1419
case MATCH => matchType(t)
1470
1420
case FORSOME => syntaxError(ExistentialTypesNoLongerSupported ()); t
1471
1421
case _ =>
1472
- if (imods.is(Erased ) && ! t.isInstanceOf [FunctionWithMods ])
1473
- syntaxError(ErasedTypesCanOnlyBeFunctionTypes (), implicitKwPos(start))
1422
+ // if (imods.is(Erased) && !t.isInstanceOf[FunctionWithMods])
1423
+ // syntaxError(ErasedTypesCanOnlyBeFunctionTypes(), implicitKwPos(start))
1474
1424
t
1475
1425
}
1476
1426
}
1477
1427
1428
+ def funArgTypesRest (first : Tree , following : () => Tree ): List [Tree ] =
1429
+ val buf = new ListBuffer [Tree ] += first
1430
+ while in.token == COMMA do
1431
+ in.nextToken()
1432
+ buf += following()
1433
+ buf.toList
1434
+
1435
+ def typAfterParens (parseRest : (List [Tree ], Modifiers ) => Tree ) =
1436
+ val start = in.offset
1437
+ in.nextToken()
1438
+ var imods = Modifiers ()
1439
+ var isValParamList = false
1440
+ if in.token == RPAREN then
1441
+ in.nextToken()
1442
+ parseRest(Nil , imods)
1443
+ else
1444
+ openParens.change(LPAREN , 1 )
1445
+ imods = modifiers(funTypeArgMods)
1446
+ val paramStart = in.offset
1447
+ val ts = funArgType() match
1448
+ case Ident (name) if name != tpnme.WILDCARD && in.token == COLON =>
1449
+ isValParamList = true
1450
+ funArgTypesRest(
1451
+ typedFunParam(paramStart, name.toTermName, imods),
1452
+ () => typedFunParam(in.offset, ident(), imods))
1453
+ case t =>
1454
+ funArgTypesRest(t, funArgType)
1455
+ openParens.change(LPAREN , - 1 )
1456
+ accept(RPAREN )
1457
+ if isValParamList || in.token == ARROW || in.token == CTXARROW then
1458
+ parseRest(ts, imods)
1459
+ else
1460
+ val ts1 =
1461
+ for t <- ts yield
1462
+ t match
1463
+ case t@ ByNameTypeTree (t1) =>
1464
+ syntaxError(ByNameParameterNotSupported (t), t.span)
1465
+ t1
1466
+ case _ =>
1467
+ t
1468
+ val tuple = atSpan(start) { makeTupleOrParens(ts1) }
1469
+ infixTypeRest(
1470
+ refinedTypeRest(
1471
+ withTypeRest(
1472
+ annotTypeRest(
1473
+ simpleTypeRest(tuple)))))
1474
+ end typAfterParens
1475
+
1478
1476
private def makeKindProjectorTypeDef (name : TypeName ): TypeDef =
1479
1477
TypeDef (name, WildcardTypeBoundsTree ()).withFlags(Param )
1480
1478
@@ -3607,24 +3605,30 @@ object Parsers {
3607
3605
3608
3606
/* -------- TEMPLATES ------------------------------------------- */
3609
3607
3608
+ def constrOrSimpleType () =
3609
+ rejectWildcardType(
3610
+ annotTypeRest(simpleType1()),
3611
+ fallbackTree = Ident (tpnme.ERROR ))
3612
+ // Using Ident(tpnme.ERROR) to avoid causing cascade errors on non-user-written code
3613
+
3610
3614
/** ConstrApp ::= SimpleType1 {Annotation} {ParArgumentExprs}
3611
3615
*/
3612
3616
val constrApp : () => Tree = () =>
3613
- val t = rejectWildcardType(annotTypeRest(simpleType1()),
3614
- fallbackTree = Ident (tpnme.ERROR ))
3615
- // Using Ident(tpnme.ERROR) to avoid causing cascade errors on non-user-written code
3617
+ val t = constrOrSimpleType()
3616
3618
if in.token == LPAREN then parArgumentExprss(wrapNew(t)) else t
3617
3619
3618
3620
/** ConstrApps ::= ConstrApp {(‘,’ | ‘with’) ConstrApp}
3619
3621
*/
3620
3622
def constrApps (commaOK : Boolean ): List [Tree ] =
3621
- val t = constrApp()
3623
+ constrAppsRest(constrApp(), commaOK)
3624
+
3625
+ def constrAppsRest (app : Tree , commaOK : Boolean ): List [Tree ] =
3622
3626
val ts =
3623
3627
if in.token == WITH || commaOK && in.token == COMMA then
3624
3628
in.nextToken()
3625
3629
constrApps(commaOK)
3626
3630
else Nil
3627
- t :: ts
3631
+ app :: ts
3628
3632
3629
3633
/** Template ::= InheritClauses [TemplateBody]
3630
3634
* InheritClauses ::= [‘extends’ ConstrApps] [‘derives’ QualId {‘,’ QualId}]
0 commit comments