Skip to content

Commit f9d63d6

Browse files
Merge pull request #10330 from dotty-staging/fix-#9515
Fix #9515: Fix handling of selftype for indentation
2 parents e73f0e4 + 5dbe2b4 commit f9d63d6

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3766,7 +3766,7 @@ object Parsers {
37663766
if (name != nme.ERROR)
37673767
self = makeSelfDef(name, tpt).withSpan(first.span)
37683768
}
3769-
in.token = EMPTY // hack to suppress INDENT insertion after `=>`
3769+
in.token = SELFARROW // suppresses INDENT insertion after `=>`
37703770
in.nextToken()
37713771
}
37723772
else {

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

+2
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,8 @@ object Scanners {
487487
if canStartIndentTokens.contains(lastToken) then
488488
currentRegion = Indented(nextWidth, Set(), lastToken, currentRegion)
489489
insert(INDENT, offset)
490+
else if lastToken == SELFARROW then
491+
currentRegion.knownWidth = nextWidth
490492
else if (lastWidth != nextWidth)
491493
errorButContinue(spaceTabMismatchMsg(lastWidth, nextWidth))
492494
currentRegion match {

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

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ object Tokens extends TokensCommon {
204204
final val QUOTE = 87; enter(QUOTE, "'")
205205

206206
final val COLONEOL = 88; enter(COLONEOL, ":", ": at eol")
207+
final val SELFARROW = 89; enter(SELFARROW, "=>") // reclassified ARROW following self-type
207208

208209
/** XML mode */
209210
final val XMLSTART = 98; enter(XMLSTART, "$XMLSTART$<") // TODO: deprecate

tests/pos/i9515.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trait C {
2+
self =>
3+
4+
class D
5+
6+
class E
7+
}

0 commit comments

Comments
 (0)