@@ -192,7 +192,9 @@ object Parsers {
192192
193193 def isIdent = in.isIdent
194194 def isIdent (name : Name ) = in.isIdent(name)
195- def isSimpleLiteral = simpleLiteralTokens contains in.token
195+ def isSimpleLiteral =
196+ simpleLiteralTokens.contains(in.token)
197+ || isIdent(nme.raw.MINUS ) && numericLitTokens.contains(in.lookahead.token)
196198 def isLiteral = literalTokens contains in.token
197199 def isNumericLit = numericLitTokens contains in.token
198200 def isTemplateIntro = templateIntroTokens contains in.token
@@ -1101,18 +1103,42 @@ object Parsers {
11011103 */
11021104 def qualId (): Tree = dotSelectors(termIdent())
11031105
1104- /** SimpleExpr ::= literal
1105- * | 'id | 'this | 'true | 'false | 'null
1106- * | null
1106+ /** Singleton ::= SimpleRef
1107+ * | SimpleLiteral
1108+ * | Singleton ‘.’ id
1109+ */
1110+ def singleton (): Tree =
1111+ if isSimpleLiteral then simpleLiteral()
1112+ else dotSelectors(simpleRef())
1113+
1114+ /** SimpleLiteral ::= [‘-’] integerLiteral
1115+ * | [‘-’] floatingPointLiteral
1116+ * | booleanLiteral
1117+ * | characterLiteral
1118+ * | stringLiteral
1119+ */
1120+ def simpleLiteral (): Tree =
1121+ if isIdent(nme.raw.MINUS ) then
1122+ val start = in.offset
1123+ in.nextToken()
1124+ literal(negOffset = start, inTypeOrSingleton = true )
1125+ else
1126+ literal(inTypeOrSingleton = true )
1127+
1128+ /** Literal ::= SimpleLiteral
1129+ * | processedStringLiteral
1130+ * | symbolLiteral
1131+ * | ‘null’
1132+ *
11071133 * @param negOffset The offset of a preceding `-' sign, if any.
1108- * If the literal is not negated, negOffset = in.offset.
1134+ * If the literal is not negated, negOffset == in.offset.
11091135 */
1110- def literal (negOffset : Int = in.offset, inPattern : Boolean = false , inType : Boolean = false , inStringInterpolation : Boolean = false ): Tree = {
1136+ def literal (negOffset : Int = in.offset, inPattern : Boolean = false , inTypeOrSingleton : Boolean = false , inStringInterpolation : Boolean = false ): Tree = {
11111137 def literalOf (token : Token ): Tree = {
11121138 val isNegated = negOffset < in.offset
11131139 def digits0 = in.removeNumberSeparators(in.strVal)
11141140 def digits = if (isNegated) " -" + digits0 else digits0
1115- if ( ! inType)
1141+ if ! inTypeOrSingleton then
11161142 token match {
11171143 case INTLIT => return Number (digits, NumberKind .Whole (in.base))
11181144 case DECILIT => return Number (digits, NumberKind .Decimal )
@@ -1333,22 +1359,33 @@ object Parsers {
13331359 case _ => false
13341360 }
13351361
1336- /** Type ::= FunType
1337- * | HkTypeParamClause ‘=>>’ Type
1338- * | MatchType
1339- * | InfixType
1340- * FunType ::= (MonoFunType | PolyFunType)
1341- * MonoFunType ::= FunArgTypes (‘=>’ | ‘?=>’) Type
1342- * PolyFunType ::= HKTypeParamClause '=>' Type
1343- * FunArgTypes ::= InfixType
1344- * | `(' [ [ ‘[using]’ ‘['erased'] FunArgType {`,' FunArgType } ] `)'
1345- * | '(' [ ‘[using]’ ‘['erased'] TypedFunParam {',' TypedFunParam } ')'
1362+ /** Type ::= FunType
1363+ * | HkTypeParamClause ‘=>>’ Type
1364+ * | FunParamClause ‘=>>’ Type
1365+ * | MatchType
1366+ * | InfixType
1367+ * FunType ::= (MonoFunType | PolyFunType)
1368+ * MonoFunType ::= FunArgTypes (‘=>’ | ‘?=>’) Type
1369+ * PolyFunType ::= HKTypeParamClause '=>' Type
1370+ * FunArgTypes ::= InfixType
1371+ * | `(' [ [ ‘[using]’ ‘['erased'] FunArgType {`,' FunArgType } ] `)'
1372+ * | '(' [ ‘[using]’ ‘['erased'] TypedFunParam {',' TypedFunParam } ')'
13461373 */
13471374 def typ (): Tree = {
13481375 val start = in.offset
13491376 var imods = Modifiers ()
13501377 def functionRest (params : List [Tree ]): Tree =
13511378 atSpan(start, in.offset) {
1379+ if in.token == TLARROW then
1380+ if ! imods.flags.isEmpty || params.isEmpty then
1381+ syntaxError(em " illegal parameter list for type lambda " , start)
1382+ in.token = ARROW
1383+ else
1384+ for case ValDef (_, tpt : ByNameTypeTree , _) <- params do
1385+ syntaxError(em " parameter of type lambda may not be call-by-name " , tpt.span)
1386+ in.nextToken()
1387+ return TermLambdaTypeTree (params.asInstanceOf [List [ValDef ]], typ())
1388+
13521389 if in.token == CTXARROW then
13531390 in.nextToken()
13541391 imods |= Given
@@ -1475,10 +1512,19 @@ object Parsers {
14751512 Span (start, start + nme.IMPLICITkw .asSimpleName.length)
14761513
14771514 /** TypedFunParam ::= id ':' Type */
1478- def typedFunParam (start : Offset , name : TermName , mods : Modifiers = EmptyModifiers ): Tree = atSpan(start) {
1479- accept(COLON )
1480- makeParameter(name, typ(), mods | Param )
1481- }
1515+ def typedFunParam (start : Offset , name : TermName , mods : Modifiers = EmptyModifiers ): ValDef =
1516+ atSpan(start) {
1517+ accept(COLON )
1518+ makeParameter(name, typ(), mods | Param )
1519+ }
1520+
1521+ /** FunParamClause ::= ‘(’ TypedFunParam {‘,’ TypedFunParam } ‘)’
1522+ */
1523+ def funParamClause (): List [ValDef ] =
1524+ inParens(commaSeparated(() => typedFunParam(in.offset, ident())))
1525+
1526+ def funParamClauses (): List [List [ValDef ]] =
1527+ if in.token == LPAREN then funParamClause() :: funParamClauses() else Nil
14821528
14831529 /** InfixType ::= RefinedType {id [nl] RefinedType}
14841530 */
@@ -1556,14 +1602,12 @@ object Parsers {
15561602 /** SimpleType ::= SimpleLiteral
15571603 * | ‘?’ SubtypeBounds
15581604 * | SimpleType1
1605+ * | SimpeType ‘(’ Singletons ‘)’ -- under language.experimental.dependent, checked in Typer
1606+ * Singletons ::= Singleton {‘,’ Singleton}
15591607 */
15601608 def simpleType (): Tree =
15611609 if isSimpleLiteral then
1562- SingletonTypeTree (literal(inType = true ))
1563- else if isIdent(nme.raw.MINUS ) && numericLitTokens.contains(in.lookahead.token) then
1564- val start = in.offset
1565- in.nextToken()
1566- SingletonTypeTree (literal(negOffset = start, inType = true ))
1610+ SingletonTypeTree (simpleLiteral())
15671611 else if in.token == USCORE then
15681612 if sourceVersion.isAtLeast(`3.1`) then
15691613 deprecationWarning(em " `_` is deprecated for wildcard arguments of types: use `?` instead " )
@@ -1576,7 +1620,11 @@ object Parsers {
15761620 else if isIdent(nme.* ) && ctx.settings.YkindProjector .value then
15771621 typeIdent()
15781622 else
1579- simpleType1()
1623+ def singletonArgs (t : Tree ): Tree =
1624+ if in.token == LPAREN
1625+ then singletonArgs(AppliedTypeTree (t, inParens(commaSeparated(singleton))))
1626+ else t
1627+ singletonArgs(simpleType1())
15801628
15811629 /** SimpleType1 ::= id
15821630 * | Singleton `.' id
@@ -2811,11 +2859,11 @@ object Parsers {
28112859 else tree1
28122860 }
28132861
2814- /** Annotation ::= `@' SimpleType {ParArgumentExprs}
2862+ /** Annotation ::= `@' SimpleType1 {ParArgumentExprs}
28152863 */
28162864 def annot (): Tree =
28172865 adjustStart(accept(AT )) {
2818- ensureApplied(parArgumentExprss(wrapNew(simpleType ())))
2866+ ensureApplied(parArgumentExprss(wrapNew(simpleType1 ())))
28192867 }
28202868
28212869 def annotations (skipNewLines : Boolean = false ): List [Tree ] = {
@@ -3348,15 +3396,16 @@ object Parsers {
33483396 argumentExprss(mkApply(Ident (nme.CONSTRUCTOR ), argumentExprs()))
33493397 }
33503398
3351- /** TypeDcl ::= id [TypeParamClause] TypeBounds [‘=’ Type]
3399+ /** TypeDcl ::= id [TypeParamClause] {FunParamClause} TypeBounds [‘=’ Type]
33523400 */
33533401 def typeDefOrDcl (start : Offset , mods : Modifiers ): Tree = {
33543402 newLinesOpt()
33553403 atSpan(start, nameStart) {
33563404 val nameIdent = typeIdent()
33573405 val tparams = typeParamClauseOpt(ParamOwner .Type )
3406+ val vparamss = funParamClauses()
33583407 def makeTypeDef (rhs : Tree ): Tree = {
3359- val rhs1 = lambdaAbstract (tparams, rhs)
3408+ val rhs1 = lambdaAbstractAll (tparams :: vparamss , rhs)
33603409 val tdef = TypeDef (nameIdent.name.toTypeName, rhs1)
33613410 if (nameIdent.isBackquoted)
33623411 tdef.pushAttachment(Backquoted , ())
0 commit comments