@@ -1521,13 +1521,15 @@ object Parsers {
1521
1521
* PolyFunType ::= HKTypeParamClause '=>' Type
1522
1522
* | HKTypeParamClause ‘->’ [CaptureSet] Type -- under pureFunctions
1523
1523
* FunTypeArgs ::= InfixType
1524
- * | `(' [ [ ‘['erased'] FunArgType {`,' FunArgType } ] `)'
1525
- * | '(' [ ‘['erased'] TypedFunParam {',' TypedFunParam } ')'
1524
+ * | `(' [ FunArgType {`,' FunArgType } ] `)'
1525
+ * | '(' [ TypedFunParam {',' TypedFunParam } ')'
1526
+ * MatchType ::= InfixType `match` <<< TypeCaseClauses >>>
1526
1527
*/
1527
1528
def typ (): Tree =
1528
1529
val start = in.offset
1529
1530
var imods = Modifiers ()
1530
- var erasedArgs : ListBuffer [Boolean ] = ListBuffer ()
1531
+ val erasedArgs : ListBuffer [Boolean ] = ListBuffer ()
1532
+
1531
1533
def functionRest (params : List [Tree ]): Tree =
1532
1534
val paramSpan = Span (start, in.lastOffset)
1533
1535
atSpan(start, in.offset) {
@@ -1556,7 +1558,8 @@ object Parsers {
1556
1558
else
1557
1559
accept(ARROW )
1558
1560
1559
- val resultType = if isPure then capturesAndResult(typ) else typ()
1561
+ val resultType =
1562
+ if isPure then capturesAndResult(typ) else typ()
1560
1563
if token == TLARROW then
1561
1564
for case ValDef (_, tpt, _) <- params do
1562
1565
if isByNameType(tpt) then
@@ -1573,99 +1576,94 @@ object Parsers {
1573
1576
Function (params, resultType)
1574
1577
}
1575
1578
1576
- var isValParamList = false
1579
+ def typeRest (t : Tree ) = in.token match
1580
+ case ARROW | CTXARROW =>
1581
+ erasedArgs.addOne(false )
1582
+ functionRest(t :: Nil )
1583
+ case MATCH =>
1584
+ matchType(t)
1585
+ case FORSOME =>
1586
+ syntaxError(ExistentialTypesNoLongerSupported ())
1587
+ t
1588
+ case _ if isPureArrow =>
1589
+ erasedArgs.addOne(false )
1590
+ functionRest(t :: Nil )
1591
+ case _ =>
1592
+ if erasedArgs.contains(true ) && ! t.isInstanceOf [FunctionWithMods ] then
1593
+ syntaxError(ErasedTypesCanOnlyBeFunctionTypes (), implicitKwPos(start))
1594
+ t
1577
1595
1578
- val t =
1579
- if (in.token == LPAREN ) {
1596
+ var isValParamList = false
1597
+ if in.token == LPAREN then
1598
+ in.nextToken()
1599
+ if in.token == RPAREN then
1580
1600
in.nextToken()
1581
- if (in.token == RPAREN ) {
1582
- in.nextToken()
1583
- functionRest(Nil )
1584
- }
1585
- else {
1586
- val paramStart = in.offset
1587
- def addErased () =
1588
- erasedArgs.addOne(isErasedKw)
1589
- if isErasedKw then { in.skipToken(); }
1590
- addErased()
1591
- val ts = in.currentRegion.withCommasExpected {
1601
+ functionRest(Nil )
1602
+ else
1603
+ val paramStart = in.offset
1604
+ def addErased () =
1605
+ erasedArgs.addOne(isErasedKw)
1606
+ if isErasedKw then in.skipToken()
1607
+ addErased()
1608
+ val args =
1609
+ in.currentRegion.withCommasExpected:
1592
1610
funArgType() match
1593
1611
case Ident (name) if name != tpnme.WILDCARD && in.isColon =>
1594
1612
isValParamList = true
1595
- def funParam (start : Offset , mods : Modifiers ) = {
1596
- atSpan(start) {
1613
+ def funParam (start : Offset , mods : Modifiers ) =
1614
+ atSpan(start):
1597
1615
addErased()
1598
1616
typedFunParam(in.offset, ident(), imods)
1599
- }
1600
- }
1601
1617
commaSeparatedRest(
1602
1618
typedFunParam(paramStart, name.toTermName, imods),
1603
1619
() => funParam(in.offset, imods))
1604
1620
case t =>
1605
- def funParam () = {
1606
- addErased()
1607
- funArgType()
1608
- }
1609
- commaSeparatedRest(t, funParam)
1610
- }
1611
- accept(RPAREN )
1612
- if isValParamList || in.isArrow || isPureArrow then
1613
- functionRest(ts)
1614
- else {
1615
- val ts1 = ts.mapConserve { t =>
1616
- if isByNameType(t) then
1617
- syntaxError(ByNameParameterNotSupported (t), t.span)
1618
- stripByNameType(t)
1619
- else
1620
- t
1621
- }
1622
- val tuple = atSpan(start) { makeTupleOrParens(ts1) }
1623
- infixTypeRest(
1624
- refinedTypeRest(
1625
- withTypeRest(
1626
- annotTypeRest(
1627
- simpleTypeRest(tuple)))))
1628
- }
1629
- }
1630
- }
1631
- else if (in.token == LBRACKET ) {
1632
- val start = in.offset
1633
- val tparams = typeParamClause(ParamOwner .TypeParam )
1634
- if (in.token == TLARROW )
1635
- atSpan(start, in.skipToken())(LambdaTypeTree (tparams, toplevelTyp()))
1636
- else if (in.token == ARROW || isPureArrow(nme.PUREARROW )) {
1637
- val arrowOffset = in.skipToken()
1638
- val body = toplevelTyp()
1639
- atSpan(start, arrowOffset) {
1640
- getFunction(body) match {
1641
- case Some (f) =>
1642
- checkFunctionNotErased(f, " poly function" )
1643
- PolyFunction (tparams, body)
1644
- case None =>
1645
- syntaxError(em " Implementation restriction: polymorphic function types must have a value parameter " , arrowOffset)
1646
- Ident (nme.ERROR .toTypeName)
1647
- }
1648
- }
1649
- }
1650
- else { accept(TLARROW ); typ() }
1651
- }
1652
- else if (in.token == INDENT ) enclosed(INDENT , typ())
1653
- else infixType()
1654
-
1655
- in.token match
1656
- case ARROW | CTXARROW =>
1657
- erasedArgs.addOne(false )
1658
- functionRest(t :: Nil )
1659
- case MATCH => matchType(t)
1660
- case FORSOME => syntaxError(ExistentialTypesNoLongerSupported ()); t
1661
- case _ =>
1662
- if isPureArrow then
1663
- erasedArgs.addOne(false )
1664
- functionRest(t :: Nil )
1621
+ def funArg () =
1622
+ erasedArgs.addOne(false )
1623
+ funArgType()
1624
+ commaSeparatedRest(t, funArg)
1625
+ accept(RPAREN )
1626
+ if isValParamList || in.isArrow || isPureArrow then
1627
+ functionRest(args)
1665
1628
else
1666
- if (erasedArgs.contains(true ) && ! t.isInstanceOf [FunctionWithMods ])
1667
- syntaxError(ErasedTypesCanOnlyBeFunctionTypes (), implicitKwPos(start))
1668
- t
1629
+ val args1 = args.mapConserve: t =>
1630
+ if isByNameType(t) then
1631
+ syntaxError(ByNameParameterNotSupported (t), t.span)
1632
+ stripByNameType(t)
1633
+ else
1634
+ t
1635
+ val tuple = atSpan(start):
1636
+ makeTupleOrParens(args1)
1637
+ typeRest :
1638
+ infixTypeRest :
1639
+ refinedTypeRest :
1640
+ withTypeRest :
1641
+ annotTypeRest :
1642
+ simpleTypeRest(tuple)
1643
+ else if in.token == LBRACKET then
1644
+ val start = in.offset
1645
+ val tparams = typeParamClause(ParamOwner .TypeParam )
1646
+ if in.token == TLARROW then
1647
+ atSpan(start, in.skipToken()):
1648
+ LambdaTypeTree (tparams, toplevelTyp())
1649
+ else if in.token == ARROW || isPureArrow(nme.PUREARROW ) then
1650
+ val arrowOffset = in.skipToken()
1651
+ val body = toplevelTyp()
1652
+ atSpan(start, arrowOffset):
1653
+ getFunction(body) match
1654
+ case Some (f) =>
1655
+ checkFunctionNotErased(f, " poly function" )
1656
+ PolyFunction (tparams, body)
1657
+ case None =>
1658
+ syntaxError(em " Implementation restriction: polymorphic function types must have a value parameter " , arrowOffset)
1659
+ Ident (nme.ERROR .toTypeName)
1660
+ else
1661
+ accept(TLARROW )
1662
+ typ()
1663
+ else if in.token == INDENT then
1664
+ enclosed(INDENT , typ())
1665
+ else
1666
+ typeRest(infixType())
1669
1667
end typ
1670
1668
1671
1669
private def makeKindProjectorTypeDef (name : TypeName ): TypeDef = {
@@ -1702,7 +1700,7 @@ object Parsers {
1702
1700
private def implicitKwPos (start : Int ): Span =
1703
1701
Span (start, start + nme.IMPLICITkw .asSimpleName.length)
1704
1702
1705
- /** TypedFunParam ::= id ':' Type */
1703
+ /** TypedFunParam ::= [`erased`] id ':' Type */
1706
1704
def typedFunParam (start : Offset , name : TermName , mods : Modifiers = EmptyModifiers ): ValDef =
1707
1705
atSpan(start) {
1708
1706
acceptColon()
@@ -2016,7 +2014,7 @@ object Parsers {
2016
2014
*/
2017
2015
def paramType (): Tree = paramTypeOf(paramValueType)
2018
2016
2019
- /** ParamValueType ::= [`into`] Type [`*']
2017
+ /** ParamValueType ::= Type [`*']
2020
2018
*/
2021
2019
def paramValueType (): Tree = {
2022
2020
val t = maybeInto(toplevelTyp)
@@ -2374,7 +2372,7 @@ object Parsers {
2374
2372
Match (t, inBracesOrIndented(caseClauses(() => caseClause())))
2375
2373
}
2376
2374
2377
- /** `match' `{' TypeCaseClauses `}'
2375
+ /** `match' <<< TypeCaseClauses >>>
2378
2376
*/
2379
2377
def matchType (t : Tree ): MatchTypeTree =
2380
2378
atSpan(startOffset(t), accept(MATCH )) {
@@ -2384,7 +2382,7 @@ object Parsers {
2384
2382
/** FunParams ::= Bindings
2385
2383
* | id
2386
2384
* | `_'
2387
- * Bindings ::= `(' [[‘erased’] Binding {`,' Binding}] `)'
2385
+ * Bindings ::= `(' [Binding {`,' Binding}] `)'
2388
2386
*/
2389
2387
def funParams (mods : Modifiers , location : Location ): List [Tree ] =
2390
2388
if in.token == LPAREN then
@@ -3126,7 +3124,7 @@ object Parsers {
3126
3124
* | AccessModifier
3127
3125
* | override
3128
3126
* | opaque
3129
- * LocalModifier ::= abstract | final | sealed | open | implicit | lazy | erased | inline | transparent
3127
+ * LocalModifier ::= abstract | final | sealed | open | implicit | lazy | inline | transparent | infix | erased
3130
3128
*/
3131
3129
def modifiers (allowed : BitSet = modifierTokens, start : Modifiers = Modifiers ()): Modifiers = {
3132
3130
@ tailrec
@@ -3283,7 +3281,7 @@ object Parsers {
3283
3281
/** ClsTermParamClause ::= ‘(’ ClsParams ‘)’ | UsingClsTermParamClause
3284
3282
* UsingClsTermParamClause::= ‘(’ ‘using’ [‘erased’] (ClsParams | ContextTypes) ‘)’
3285
3283
* ClsParams ::= ClsParam {‘,’ ClsParam}
3286
- * ClsParam ::= {Annotation}
3284
+ * ClsParam ::= {Annotation} [{Modifier} (‘val’ | ‘var’)] Param
3287
3285
*
3288
3286
* TypelessClause ::= DefTermParamClause
3289
3287
* | UsingParamClause
0 commit comments