@@ -1806,8 +1806,8 @@ object Parsers {
1806
1806
*/
1807
1807
def infixType (): Tree = infixTypeRest(refinedType())
1808
1808
1809
- def infixTypeRest (t : Tree ): Tree =
1810
- infixOps(t, canStartInfixTypeTokens, refinedTypeFn , Location .ElseWhere , ParseKind .Type ,
1809
+ def infixTypeRest (t : Tree , operand : Location => Tree = refinedTypeFn ): Tree =
1810
+ infixOps(t, canStartInfixTypeTokens, operand , Location .ElseWhere , ParseKind .Type ,
1811
1811
isOperator = ! followingIsVararg() && ! isPureArrow
1812
1812
&& nextCanFollowOperator(canStartInfixTypeTokens))
1813
1813
@@ -1872,6 +1872,10 @@ object Parsers {
1872
1872
*/
1873
1873
def annotType (): Tree = annotTypeRest(simpleType())
1874
1874
1875
+ /** AnnotType1 ::= SimpleType1 {Annotation}
1876
+ */
1877
+ def annotType1 (): Tree = annotTypeRest(simpleType1())
1878
+
1875
1879
def annotTypeRest (t : Tree ): Tree =
1876
1880
if (in.token == AT )
1877
1881
annotTypeRest(atSpan(startOffset(t)) {
@@ -4097,8 +4101,10 @@ object Parsers {
4097
4101
syntaxError(em " extension clause can only define methods " , stat.span)
4098
4102
}
4099
4103
4100
- /** GivenDef ::= [GivenSig] (AnnotType [‘=’ Expr] | StructuralInstance)
4101
- * GivenSig ::= [id] [DefTypeParamClause] {UsingParamClauses} ‘:’
4104
+ /** GivenDef ::= [GivenSig] (GivenType [‘=’ Expr] | StructuralInstance)
4105
+ * GivenSig ::= [id] [DefTypeParamClause] {UsingParamClauses} ‘:’
4106
+ * GivenType ::= AnnotType1 {id [nl] AnnotType1}
4107
+ * StructuralInstance ::= ConstrApp {‘with’ ConstrApp} [‘with’ WithTemplateBody]
4102
4108
*/
4103
4109
def givenDef (start : Offset , mods : Modifiers , givenMod : Mod ) = atSpan(start, nameStart) {
4104
4110
var mods1 = addMod(mods, givenMod)
@@ -4124,8 +4130,12 @@ object Parsers {
4124
4130
val noParams = tparams.isEmpty && vparamss.isEmpty
4125
4131
if ! (name.isEmpty && noParams) then acceptColon()
4126
4132
val parents =
4127
- if isSimpleLiteral then rejectWildcardType(annotType()) :: Nil
4128
- else refinedTypeRest(constrApp()) :: withConstrApps()
4133
+ if isSimpleLiteral then
4134
+ rejectWildcardType(annotType()) :: Nil
4135
+ else constrApp() match
4136
+ case parent : Apply => parent :: withConstrApps()
4137
+ case parent if in.isIdent => infixTypeRest(parent, _ => annotType1()) :: Nil
4138
+ case parent => parent :: withConstrApps()
4129
4139
val parentsIsType = parents.length == 1 && parents.head.isType
4130
4140
if in.token == EQUALS && parentsIsType then
4131
4141
accept(EQUALS )
@@ -4219,10 +4229,10 @@ object Parsers {
4219
4229
4220
4230
/* -------- TEMPLATES ------------------------------------------- */
4221
4231
4222
- /** ConstrApp ::= SimpleType1 {Annotation} {ParArgumentExprs}
4232
+ /** ConstrApp ::= AnnotType1 {ParArgumentExprs}
4223
4233
*/
4224
4234
val constrApp : () => Tree = () =>
4225
- val t = rejectWildcardType(annotTypeRest(simpleType1() ),
4235
+ val t = rejectWildcardType(annotType1( ),
4226
4236
fallbackTree = Ident (tpnme.ERROR ))
4227
4237
// Using Ident(tpnme.ERROR) to avoid causing cascade errors on non-user-written code
4228
4238
if in.token == LPAREN then parArgumentExprss(wrapNew(t)) else t
0 commit comments