@@ -573,7 +573,7 @@ object Parsers {
573573 def inBraces [T ](body : => T ): T = enclosed(LBRACE , body)
574574 def inBrackets [T ](body : => T ): T = enclosed(LBRACKET , body)
575575
576- def inBracesOrIndented [T ](body : => T ): T =
576+ def inBracesOrIndented [T ](body : => T , rewriteWithColon : Boolean = false ): T =
577577 if (in.token == INDENT ) {
578578 val rewriteToBraces =
579579 in.rewriteNoIndent &&
@@ -582,12 +582,12 @@ object Parsers {
582582 else enclosed(INDENT , body)
583583 }
584584 else
585- if (in.rewriteToIndent) bracesToIndented(body)
585+ if (in.rewriteToIndent) bracesToIndented(body, rewriteWithColon )
586586 else inBraces(body)
587587
588- def inDefScopeBraces [T ](body : => T ): T = {
588+ def inDefScopeBraces [T ](body : => T , rewriteWithColon : Boolean = false ): T = {
589589 val saved = lastStatOffset
590- try inBracesOrIndented(body)
590+ try inBracesOrIndented(body, rewriteWithColon )
591591 finally lastStatOffset = saved
592592 }
593593
@@ -775,8 +775,9 @@ object Parsers {
775775 * rewriting back to braces does not work after `=>` (since in most cases braces are omitted
776776 * after a `=>` it would be annoying if braces were inserted).
777777 */
778- def bracesToIndented [T ](body : => T ): T = {
779- val colonRequired = possibleColonOffset == in.lastOffset
778+ def bracesToIndented [T ](body : => T , rewriteWithColon : Boolean ): T = {
779+ val underColonSyntax = possibleColonOffset == in.lastOffset
780+ val colonRequired = rewriteWithColon || underColonSyntax
780781 val (startOpening, endOpening) = startingElimRegion(colonRequired)
781782 val isOutermost = in.currentRegion.isOutermost
782783 def allBraces (r : Region ): Boolean = r match {
@@ -795,10 +796,10 @@ object Parsers {
795796 }
796797 })
797798 canRewrite &= (in.isAfterLineEnd || statCtdTokens.contains(in.token)) // test (5)
798- if (canRewrite && (! colonRequired || in.colonSyntax)) {
799+ if (canRewrite && (! underColonSyntax || in.colonSyntax)) {
799800 val openingPatchStr =
800- if ( ! colonRequired) " "
801- else if ( testChar(startOpening - 1 , Chars .isOperatorPart(_))) " :"
801+ if ! colonRequired then " "
802+ else if testChar(startOpening - 1 , Chars .isOperatorPart(_)) then " :"
802803 else " :"
803804 val (startClosing, endClosing) = closingElimRegion()
804805 patch(source, Span (startOpening, endOpening), openingPatchStr)
@@ -1736,7 +1737,8 @@ object Parsers {
17361737
17371738 /** Refinement ::= `{' RefineStatSeq `}'
17381739 */
1739- def refinement (): List [Tree ] = inBracesOrIndented(refineStatSeq())
1740+ def refinement (): List [Tree ] =
1741+ inBracesOrIndented(refineStatSeq(), rewriteWithColon = true )
17401742
17411743 /** TypeBounds ::= [`>:' Type] [`<:' Type]
17421744 */
@@ -2469,11 +2471,10 @@ object Parsers {
24692471 val pos = t.sourcePos
24702472 pos.startLine < pos.endLine
24712473 }
2472- if (rewriteToNewSyntax( Span (start)) && (leading == LBRACE || ! hasMultiLineEnum)) {
2474+ if in.newSyntax && in.rewrite && (leading == LBRACE || ! hasMultiLineEnum) then
24732475 // Don't rewrite if that could change meaning of newlines
24742476 newLinesOpt()
24752477 dropParensOrBraces(start, if (in.token == YIELD || in.token == DO ) " " else " do" )
2476- }
24772478 }
24782479 in.observeIndented()
24792480 res
@@ -3687,7 +3688,7 @@ object Parsers {
36873688 Template (constr, parents, derived, self, stats)
36883689
36893690 def templateBody (): (ValDef , List [Tree ]) =
3690- val r = inDefScopeBraces { templateStatSeq() }
3691+ val r = inDefScopeBraces( templateStatSeq(), rewriteWithColon = true )
36913692 if in.token == WITH then
36923693 syntaxError(EarlyDefinitionsNotSupported ())
36933694 in.nextToken()
@@ -3706,7 +3707,7 @@ object Parsers {
37063707 def packaging (start : Int ): Tree =
37073708 val pkg = qualId()
37083709 possibleTemplateStart()
3709- val stats = inDefScopeBraces(topStatSeq())
3710+ val stats = inDefScopeBraces(topStatSeq(), rewriteWithColon = true )
37103711 makePackaging(start, pkg, stats)
37113712
37123713 /** TopStatSeq ::= TopStat {semi TopStat}
@@ -3898,7 +3899,7 @@ object Parsers {
38983899 if in.token == EOF then
38993900 ts += makePackaging(start, pkg, List ())
39003901 else if in.isNestedStart then
3901- ts += inDefScopeBraces(makePackaging(start, pkg, topStatSeq()))
3902+ ts += inDefScopeBraces(makePackaging(start, pkg, topStatSeq()), rewriteWithColon = true )
39023903 continue = true
39033904 else
39043905 acceptStatSep()
0 commit comments