Skip to content

Commit 520b41d

Browse files
committed
Silence initialization checker
1 parent 40c2db6 commit 520b41d

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,14 @@ object Parsers:
161161
else if (in.token == RBRACE || in.token == OUTDENT) openBraces -= 1
162162
in.nextToken()
163163

164-
class Parser private[parsing] (source: SourceFile, allowRewrite: Boolean = true)(using Context) extends ParserCommon(source) {
164+
class Parser private[Parsers] (source: SourceFile, allowRewrite: Boolean = true)(using Context) extends ParserCommon(source) {
165165

166-
val in: Scanner = new Scanner(source, profile = Profile.current, allowRewrite = allowRewrite)
166+
val in: Scanner = createScanner()
167167
// in.debugTokenStream = true // uncomment to see the token stream of the standard scanner, but not syntax highlighting
168168

169+
def createScanner() =
170+
new Scanner(source, profile = Profile.current, allowRewrite = allowRewrite)
171+
169172
/** This is the general parse entry point.
170173
*/
171174
def parse(): Tree = {
@@ -4063,19 +4066,17 @@ object Parsers:
40634066
}
40644067

40654068
/** The Scala parser that can rewrite to indent */
4066-
class ToIndentParser(source: SourceFile)(using Context) extends Parser(source):
4067-
class ToIndentScanner(source: SourceFile)(using Context) extends Scanner(source):
4068-
/** A copy of the previous token */
4069-
var prev: TokenData = Scanners.newTokenData
4069+
private class ToIndentParser(source: SourceFile)(using Context) extends Parser(source):
40704070

4071+
override def createScanner(): Scanner = new Scanner(source):
40714072
override def nextToken(): Unit =
40724073
if token != EMPTY then patchIndent()
40734074
prev = saveCopy
40744075
super.nextToken()
4075-
end ToIndentScanner
40764076

4077-
override val in: ToIndentScanner = new ToIndentScanner(source)
40784077
assert(in.rewriteToIndent)
4078+
4079+
private var prev: TokenData = Scanners.newTokenData
40794080

40804081
/** The last offset where a colon at the end of line would be required if a subsequent { ... }
40814082
* block would be converted to an indentation region. */
@@ -4120,7 +4121,7 @@ object Parsers:
41204121
* 7. last token is not a leading operator
41214122
*/
41224123
private def bracesToIndented[T](body: => T, rewriteWithColon: Boolean): T =
4123-
val prevSaved = in.prev.saveCopy
4124+
val prevSaved = prev.saveCopy
41244125
val lastOffsetSaved = in.lastOffset
41254126
val underColonSyntax = possibleColonOffset == in.lastOffset
41264127
val colonRequired = rewriteWithColon || underColonSyntax

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ object Scanners:
14571457

14581458
/* Initialization: read first char, then first token */
14591459
nextChar()
1460-
nextToken()
1460+
(this: @unchecked).nextToken()
14611461
currentRegion = topLevelRegion(indentWidth(offset))
14621462
end Scanner
14631463

compiler/test/dotty/tools/dotc/parsing/ModifiersParsingTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object ModifiersParsingTest {
1717
given Context = (new ContextBase).initialCtx
1818

1919
def parse(code: String): Tree = {
20-
val (_, stats) = new Parser(SourceFile.virtual("<meta>", code)).templateStatSeq()
20+
val (_, stats) = Parsers.parser(SourceFile.virtual("<meta>", code)).templateStatSeq()
2121
stats match { case List(stat) => stat; case stats => Thicket(stats) }
2222
}
2323

compiler/test/dotty/tools/dotc/parsing/ParserTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ParserTest extends DottyTest {
2525

2626
private def parseSource(source: SourceFile): Tree = {
2727
//println("***** parsing " + source.file)
28-
val parser = new Parser(source)
28+
val parser = Parsers.parser(source)
2929
val tree = parser.parse()
3030
parsed += 1
3131
parsedTrees += tree

0 commit comments

Comments
 (0)