From 5dbe2b44bdf5162dbffac055fe3c35f779c26679 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 16 Nov 2020 11:17:34 +0100 Subject: [PATCH] Fix #9515: Fix handling of selftype for indentation The indentation of the self type does not matter anymore; it's the next token after the `=>` that determines the indentation width. --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- compiler/src/dotty/tools/dotc/parsing/Scanners.scala | 2 ++ compiler/src/dotty/tools/dotc/parsing/Tokens.scala | 1 + tests/pos/i9515.scala | 7 +++++++ 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i9515.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 39eda0800c44..4e5f601612f4 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -3766,7 +3766,7 @@ object Parsers { if (name != nme.ERROR) self = makeSelfDef(name, tpt).withSpan(first.span) } - in.token = EMPTY // hack to suppress INDENT insertion after `=>` + in.token = SELFARROW // suppresses INDENT insertion after `=>` in.nextToken() } else { diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 4c902b0574e2..856b63e05844 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -487,6 +487,8 @@ object Scanners { if canStartIndentTokens.contains(lastToken) then currentRegion = Indented(nextWidth, Set(), lastToken, currentRegion) insert(INDENT, offset) + else if lastToken == SELFARROW then + currentRegion.knownWidth = nextWidth else if (lastWidth != nextWidth) errorButContinue(spaceTabMismatchMsg(lastWidth, nextWidth)) currentRegion match { diff --git a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala index 7f5944c871ce..3bd14654260e 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala @@ -204,6 +204,7 @@ object Tokens extends TokensCommon { final val QUOTE = 87; enter(QUOTE, "'") final val COLONEOL = 88; enter(COLONEOL, ":", ": at eol") + final val SELFARROW = 89; enter(SELFARROW, "=>") // reclassified ARROW following self-type /** XML mode */ final val XMLSTART = 98; enter(XMLSTART, "$XMLSTART$<") // TODO: deprecate diff --git a/tests/pos/i9515.scala b/tests/pos/i9515.scala new file mode 100644 index 000000000000..ce57a5377f94 --- /dev/null +++ b/tests/pos/i9515.scala @@ -0,0 +1,7 @@ +trait C { +self => + + class D + + class E +}