@@ -1806,8 +1806,8 @@ object Parsers {
18061806 */
18071807 def infixType (): Tree = infixTypeRest(refinedType())
18081808
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 ,
18111811 isOperator = ! followingIsVararg() && ! isPureArrow
18121812 && nextCanFollowOperator(canStartInfixTypeTokens))
18131813
@@ -1872,6 +1872,10 @@ object Parsers {
18721872 */
18731873 def annotType (): Tree = annotTypeRest(simpleType())
18741874
1875+ /** AnnotType1 ::= SimpleType1 {Annotation}
1876+ */
1877+ def annotType1 (): Tree = annotTypeRest(simpleType1())
1878+
18751879 def annotTypeRest (t : Tree ): Tree =
18761880 if (in.token == AT )
18771881 annotTypeRest(atSpan(startOffset(t)) {
@@ -4097,8 +4101,10 @@ object Parsers {
40974101 syntaxError(em " extension clause can only define methods " , stat.span)
40984102 }
40994103
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]
41024108 */
41034109 def givenDef (start : Offset , mods : Modifiers , givenMod : Mod ) = atSpan(start, nameStart) {
41044110 var mods1 = addMod(mods, givenMod)
@@ -4124,8 +4130,12 @@ object Parsers {
41244130 val noParams = tparams.isEmpty && vparamss.isEmpty
41254131 if ! (name.isEmpty && noParams) then acceptColon()
41264132 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()
41294139 val parentsIsType = parents.length == 1 && parents.head.isType
41304140 if in.token == EQUALS && parentsIsType then
41314141 accept(EQUALS )
@@ -4219,10 +4229,10 @@ object Parsers {
42194229
42204230/* -------- TEMPLATES ------------------------------------------- */
42214231
4222- /** ConstrApp ::= SimpleType1 {Annotation} {ParArgumentExprs}
4232+ /** ConstrApp ::= AnnotType1 {ParArgumentExprs}
42234233 */
42244234 val constrApp : () => Tree = () =>
4225- val t = rejectWildcardType(annotTypeRest(simpleType1() ),
4235+ val t = rejectWildcardType(annotType1( ),
42264236 fallbackTree = Ident (tpnme.ERROR ))
42274237 // Using Ident(tpnme.ERROR) to avoid causing cascade errors on non-user-written code
42284238 if in.token == LPAREN then parArgumentExprss(wrapNew(t)) else t
0 commit comments