Skip to content

Commit 3549ff2

Browse files
committed
Silence initialization checker
1 parent 0c10980 commit 3549ff2

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

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

+10-9
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,14 @@ object Parsers {
168168
}
169169
}
170170

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

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

176+
def createScanner() =
177+
new Scanner(source, profile = Profile.current, allowRewrite = allowRewrite)
178+
176179
/** This is the general parse entry point.
177180
*/
178181
def parse(): Tree = {
@@ -4319,19 +4322,17 @@ object Parsers {
43194322
}
43204323

43214324
/** The Scala parser that can rewrite to indent */
4322-
class ToIndentParser(source: SourceFile)(using Context) extends Parser(source):
4323-
class ToIndentScanner(source: SourceFile)(using Context) extends Scanner(source):
4324-
/** A copy of the previous token */
4325-
var prev: TokenData = Scanners.newTokenData
4325+
private class ToIndentParser(source: SourceFile)(using Context) extends Parser(source):
43264326

4327+
override def createScanner(): Scanner = new Scanner(source):
43274328
override def nextToken(): Unit =
43284329
if token != EMPTY then patchIndent()
43294330
prev = saveCopy
43304331
super.nextToken()
4331-
end ToIndentScanner
43324332

4333-
override val in: ToIndentScanner = new ToIndentScanner(source)
43344333
assert(in.rewriteToIndent)
4334+
4335+
private var prev: TokenData = Scanners.newTokenData
43354336

43364337
/** The last offset where a colon at the end of line would be required if a subsequent { ... }
43374338
* block would be converted to an indentation region. */
@@ -4379,7 +4380,7 @@ object Parsers {
43794380
* 7. last token is not a leading operator
43804381
*/
43814382
private def bracesToIndented[T](body: => T, rewriteWithColon: Boolean): T =
4382-
val prevSaved = in.prev.saveCopy
4383+
val prevSaved = prev.saveCopy
43834384
val lastOffsetSaved = in.lastOffset
43844385
val underColonSyntax = possibleColonOffset == in.lastOffset
43854386
val colonRequired = rewriteWithColon || underColonSyntax

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ object Scanners {
15531553

15541554
/* Initialization: read first char, then first token */
15551555
nextChar()
1556-
nextToken()
1556+
(this: @unchecked).nextToken()
15571557
currentRegion = topLevelRegion(indentWidth(offset))
15581558
}
15591559
end Scanner

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

+1-1
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

+1-1
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)