Skip to content

Commit 327a253

Browse files
author
Lucy Martin
committed
Refining the previous to only apply to symbolic methods, not quoted, standard or op-suffix method names
1 parent 2128990 commit 327a253

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -814,8 +814,8 @@ object Parsers {
814814
* 6. the opening brace does not follow a `=>`. The reason for this condition is that
815815
* rewriting back to braces does not work after `=>` (since in most cases braces are omitted
816816
* after a `=>` it would be annoying if braces were inserted).
817-
* 7. not a code block being the input to a direct function call `inst method {\n expr \n}` cannot become
818-
* `inst method :\n expr`
817+
* 7. not a code block being the input to a direct symbolic function call `inst method {\n expr \n}` cannot
818+
* become `inst method :\n expr` for a fully symbolic method
819819
*/
820820
def bracesToIndented[T](body: => T, rewriteWithColon: Boolean): T = {
821821
val underColonSyntax = possibleColonOffset == in.lastOffset
@@ -830,16 +830,24 @@ object Parsers {
830830
var canRewrite = allBraces(in.currentRegion) && // test (1)
831831
!testChars(in.lastOffset - 3, " =>") // test(6)
832832

833-
def isStartOfFunction: Boolean =
834-
opStack.headOption.exists(x => x.offset > startOpening && x.offset < endOpening)
833+
def isStartOfSymbolicFunction: Boolean =
834+
opStack.headOption.exists { x =>
835+
val bq = x.operator.isBackquoted
836+
val op = x.operator.name.toSimpleName.decode.forall {
837+
Chars.isOperatorPart
838+
}
839+
val loc = startOpening < x.offset && x.offset < endOpening
840+
val res = !bq && op && loc
841+
res
842+
}
835843
val t = enclosed(LBRACE, {
836844
canRewrite &= in.isAfterLineEnd // test (2)
837845
val curOffset = in.offset
838846
try {
839847
val bodyResolved = body
840848
bodyResolved match
841849
case x:(Match | Block) =>
842-
canRewrite &= !isStartOfFunction // test (7)
850+
canRewrite &= !isStartOfSymbolicFunction // test (7)
843851
case _ =>
844852
bodyResolved
845853
}

tests/rewrites/i20002.check

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ object Reactions:
55
case 1 =>
66
}
77

8+
Reactions run:
9+
case 0 =>
10+
case 1 =>
11+
12+
Reactions run_+ :
13+
case 0 =>
14+
case 1 =>
15+
16+
Reactions `+=`:
17+
case 0 =>
18+
case 1 =>
19+
820
def bar: Int = ???
921

1022
bar match
@@ -27,6 +39,13 @@ object Reactions:
2739
Reactions += {
2840
partialFunction
2941
}
42+
3043
def +=(f: PartialFunction[Int, Unit]) =
3144
???
3245

46+
def run (f: PartialFunction[Int, Unit]) =
47+
???
48+
49+
def run_+ (f: PartialFunction[Int, Unit]) =
50+
???
51+

tests/rewrites/i20002.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ object Reactions {
55
case 1 =>
66
}
77

8+
Reactions run {
9+
case 0 =>
10+
case 1 =>
11+
}
12+
13+
Reactions run_+ {
14+
case 0 =>
15+
case 1 =>
16+
}
17+
18+
Reactions `+=` {
19+
case 0 =>
20+
case 1 =>
21+
}
22+
823
def bar: Int = ???
924

1025
bar match {
@@ -31,8 +46,17 @@ object Reactions {
3146
partialFunction
3247
}
3348
}
49+
3450
def +=(f: PartialFunction[Int, Unit]) = {
3551
???
3652
}
3753

54+
def run (f: PartialFunction[Int, Unit]) = {
55+
???
56+
}
57+
58+
def run_+ (f: PartialFunction[Int, Unit]) = {
59+
???
60+
}
61+
3862
}

0 commit comments

Comments
 (0)