Skip to content

Commit 43f276c

Browse files
committed
Allow types applied to terms in syntax and parser
1 parent a60d1c2 commit 43f276c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,8 @@ object Parsers {
783783
refinedTypeRest(
784784
withTypeRest(
785785
annotTypeRest(
786-
simpleTypeRest(tuple)))))
786+
appliedTypeRest(
787+
simpleTypeRest(tuple))))))
787788
}
788789
}
789790
}
@@ -846,14 +847,20 @@ object Parsers {
846847
}
847848
else t
848849

849-
/** AnnotType ::= SimpleType {Annotation}
850+
/** AnnotType ::= AppliedType {Annotation}
850851
*/
851-
def annotType(): Tree = annotTypeRest(simpleType())
852+
def annotType(): Tree = annotTypeRest(appliedType())
852853

853854
def annotTypeRest(t: Tree): Tree =
854855
if (in.token == AT) annotTypeRest(atPos(startOffset(t)) { Annotated(t, annot()) })
855856
else t
856857

858+
/** AppiedType ::= SimpleType {ParArgumentExprs}
859+
*/
860+
def appliedType(): Tree = appliedTypeRest(simpleType())
861+
862+
def appliedTypeRest(t: Tree) = parArgumentExprss(t)
863+
857864
/** SimpleType ::= SimpleType TypeArgs
858865
* | SimpleType `#' id
859866
* | StableId
@@ -2312,11 +2319,11 @@ object Parsers {
23122319

23132320
/* -------- TEMPLATES ------------------------------------------- */
23142321

2315-
/** ConstrApp ::= SimpleType {ParArgumentExprs}
2322+
/** ConstrApp ::= SimpleType {Annotation} {ParArgumentExprs}
23162323
*/
23172324
val constrApp = () => {
23182325
// Using Ident(nme.ERROR) to avoid causing cascade errors on non-user-written code
2319-
val t = checkWildcard(annotType(), fallbackTree = Ident(nme.ERROR))
2326+
val t = checkWildcard(annotTypeRest(simpleType()), fallbackTree = Ident(nme.ERROR))
23202327
if (in.token == LPAREN) parArgumentExprss(wrapNew(t))
23212328
else t
23222329
}

docs/docs/internals/syntax.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ TypedFunParam ::= id ‘:’ Type
128128
InfixType ::= RefinedType {id [nl] RefinedType} InfixOp(t1, op, t2)
129129
RefinedType ::= WithType {[nl] Refinement} RefinedTypeTree(t, ds)
130130
WithType ::= AnnotType {‘with’ AnnotType} (deprecated)
131-
AnnotType ::= SimpleType {Annotation} Annotated(t, annot)
131+
AnnotType ::= AppliedType {Annotation} Annotated(t, annot)
132+
AppliedType ::= SimpleType {ParArgumentExprs} Apply(t, args)
132133
SimpleType ::= SimpleType TypeArgs AppliedTypeTree(t, args)
133134
| SimpleType ‘#’ id Select(t, name)
134135
| StableId
@@ -337,7 +338,7 @@ EnumDef ::= id ClassConstr [‘extends’ [ConstrApps]] EnumBody
337338
TemplateOpt ::= [‘extends’ Template | [nl] TemplateBody]
338339
Template ::= ConstrApps [TemplateBody] | TemplateBody Template(constr, parents, self, stats)
339340
ConstrApps ::= ConstrApp {‘with’ ConstrApp}
340-
ConstrApp ::= AnnotType {ArgumentExprs} Apply(tp, args)
341+
ConstrApp ::= SimpleType {Annotation} {ParArgumentExprs} Apply(tp, args)
341342
ConstrExpr ::= SelfInvocation
342343
| ConstrBlock
343344
SelfInvocation ::= ‘this’ ArgumentExprs {ArgumentExprs}

0 commit comments

Comments
 (0)