@@ -575,22 +575,26 @@ object Parsers {
575
575
}
576
576
else recur(operand())
577
577
}
578
- else if (in.token == GIVEN ) {
578
+ else if (in.token == GIVEN && ! isType ) {
579
579
val top1 = reduceStack(base, top, minInfixPrec, leftAssoc = true , nme.WITHkw , isType)
580
580
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))
588
582
}
589
583
else reduceStack(base, top, minPrec, leftAssoc = true , in.name, isType)
590
584
591
585
recur(first)
592
586
}
593
587
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
+
594
598
/* -------- IDENTIFIERS AND LITERALS ------------------------------------------- */
595
599
596
600
/** Accept identifier and return its name as a term name. */
@@ -2710,13 +2714,43 @@ object Parsers {
2710
2714
2711
2715
/* -------- TEMPLATES ------------------------------------------- */
2712
2716
2713
- /** ConstrApp ::= SimpleType {ParArgumentExprs}
2717
+ /** SimpleConstrApp ::= AnnotType {ParArgumentExprs}
2718
+ * ConstrApp ::= SimpleConstrApp
2719
+ * | ‘(’ SimpleConstrApp {‘given’ (PrefixExpr | ParArgumentExprs)} ‘)’
2714
2720
*/
2715
2721
val constrApp : () => Tree = () => {
2716
- // Using Ident(nme.ERROR) to avoid causing cascade errors on non-user-written code
2717
- val t = rejectWildcardType(annotType(), fallbackTree = Ident (nme.ERROR ))
2718
- if (in.token == LPAREN ) parArgumentExprss(wrapNew(t))
2719
- else t
2722
+
2723
+ def isAnnotType (t : Tree ) = t match {
2724
+ case _ : Ident
2725
+ | _ : Select
2726
+ | _ : AppliedTypeTree
2727
+ | _ : Tuple
2728
+ | _ : Parens
2729
+ | _ : RefinedTypeTree
2730
+ | _ : SingletonTypeTree
2731
+ | _ : TypSplice
2732
+ | _ : Annotated => true
2733
+ case _ => false
2734
+ }
2735
+
2736
+ def givenArgs (t : Tree ): Tree = {
2737
+ if (in.token == GIVEN ) givenArgs(applyGiven(t, prefixExpr)) else t
2738
+ }
2739
+
2740
+ if (in.token == LPAREN )
2741
+ inParens {
2742
+ val t = toplevelTyp()
2743
+ if (isAnnotType(t))
2744
+ if (in.token == LPAREN ) givenArgs(parArgumentExprss(wrapNew(t)))
2745
+ else if (in.token == GIVEN ) givenArgs(wrapNew(t))
2746
+ else t
2747
+ else Parens (t)
2748
+ }
2749
+ else {
2750
+ val t = rejectWildcardType(annotType(), fallbackTree = Ident (nme.ERROR ))
2751
+ // Using Ident(nme.ERROR) to avoid causing cascade errors on non-user-written code
2752
+ if (in.token == LPAREN ) parArgumentExprss(wrapNew(t)) else t
2753
+ }
2720
2754
}
2721
2755
2722
2756
/** ConstrApps ::= ConstrApp {‘with’ ConstrApp} (to be deprecated in 3.1)
0 commit comments