@@ -575,22 +575,26 @@ object Parsers {
575575 }
576576 else recur(operand())
577577 }
578- else if (in.token == GIVEN ) {
578+ else if (in.token == GIVEN && ! isType ) {
579579 val top1 = reduceStack(base, top, minInfixPrec, leftAssoc = true , nme.WITHkw , isType)
580580 assert(opStack `eq` base)
581- val app = atSpan(startOffset(top1), in.offset) {
582- in.nextToken()
583- val args = if (in.token == LPAREN ) parArgumentExprs() else operand() :: Nil
584- Apply (top, args)
585- }
586- app.pushAttachment(ApplyGiven , ())
587- recur(app)
581+ recur(applyGiven(top1, operand))
588582 }
589583 else reduceStack(base, top, minPrec, leftAssoc = true , in.name, isType)
590584
591585 recur(first)
592586 }
593587
588+ def applyGiven (t : Tree , operand : () => Tree ): Tree = {
589+ val app = atSpan(startOffset(t), in.offset) {
590+ in.nextToken()
591+ val args = if (in.token == LPAREN ) parArgumentExprs() else operand() :: Nil
592+ Apply (t, args)
593+ }
594+ app.pushAttachment(ApplyGiven , ())
595+ app
596+ }
597+
594598/* -------- IDENTIFIERS AND LITERALS ------------------------------------------- */
595599
596600 /** Accept identifier and return its name as a term name. */
@@ -2266,7 +2270,8 @@ object Parsers {
22662270 val tps = commaSeparated(() => annotType())
22672271 var counter = nparams
22682272 def nextIdx = { counter += 1 ; counter }
2269- val params = tps.map(makeSyntheticParameter(nextIdx, _, Given | Implicit ))
2273+ val paramFlags = if (ofClass) Private | Local | ParamAccessor else Param
2274+ val params = tps.map(makeSyntheticParameter(nextIdx, _, paramFlags | Synthetic | Given | Implicit ))
22702275 params :: recur(firstClause = false , nparams + params.length)
22712276 }
22722277 else Nil
@@ -2724,13 +2729,43 @@ object Parsers {
27242729
27252730/* -------- TEMPLATES ------------------------------------------- */
27262731
2727- /** ConstrApp ::= SimpleType {ParArgumentExprs}
2732+ /** SimpleConstrApp ::= AnnotType {ParArgumentExprs}
2733+ * ConstrApp ::= SimpleConstrApp
2734+ * | ‘(’ SimpleConstrApp {‘given’ (PrefixExpr | ParArgumentExprs)} ‘)’
27282735 */
27292736 val constrApp : () => Tree = () => {
2730- // Using Ident(nme.ERROR) to avoid causing cascade errors on non-user-written code
2731- val t = rejectWildcardType(annotType(), fallbackTree = Ident (nme.ERROR ))
2732- if (in.token == LPAREN ) parArgumentExprss(wrapNew(t))
2733- else t
2737+
2738+ def isAnnotType (t : Tree ) = t match {
2739+ case _ : Ident
2740+ | _ : Select
2741+ | _ : AppliedTypeTree
2742+ | _ : Tuple
2743+ | _ : Parens
2744+ | _ : RefinedTypeTree
2745+ | _ : SingletonTypeTree
2746+ | _ : TypSplice
2747+ | _ : Annotated => true
2748+ case _ => false
2749+ }
2750+
2751+ def givenArgs (t : Tree ): Tree = {
2752+ if (in.token == GIVEN ) givenArgs(applyGiven(t, prefixExpr)) else t
2753+ }
2754+
2755+ if (in.token == LPAREN )
2756+ inParens {
2757+ val t = toplevelTyp()
2758+ if (isAnnotType(t))
2759+ if (in.token == LPAREN ) givenArgs(parArgumentExprss(wrapNew(t)))
2760+ else if (in.token == GIVEN ) givenArgs(wrapNew(t))
2761+ else t
2762+ else Parens (t)
2763+ }
2764+ else {
2765+ val t = rejectWildcardType(annotType(), fallbackTree = Ident (nme.ERROR ))
2766+ // Using Ident(nme.ERROR) to avoid causing cascade errors on non-user-written code
2767+ if (in.token == LPAREN ) parArgumentExprss(wrapNew(t)) else t
2768+ }
27342769 }
27352770
27362771 /** ConstrApps ::= ConstrApp {‘with’ ConstrApp} (to be deprecated in 3.1)
0 commit comments