Skip to content

Initialization error in Scanner #7660

Closed
@liufengyun

Description

@liufengyun

minimized code

    class LookaheadScanner(indent: Boolean = false) extends Scanner(source, offset) {
      override val indentSyntax = indent
      /// ...
    }

Trace that leads to the violation:

[warn] -- Warning: dotty/compiler/src/dotty/tools/dotc/parsing/Scanners.scala:885:34
[warn] 885 |      override val indentSyntax = indent
[warn]     |                                  ^
[warn]     |Access non-initialized field LookaheadScanner.this.indentSyntax. Calling trace:
[warn]     | -> class LookaheadScanner(indent: Boolean = false) extends Scanner(source, offset) {	[Scanners.scala:884 ]
[warn]     |  -> nextToken()	[Scanners.scala:1323 ]
[warn]     |   -> if (isAfterLineEnd) handleNewLine(lastToken)	[Scanners.scala:311 ]
[warn]     |    -> indentIsSignificant = indentSyntax	[ Scanners.scala:484]

expectation

The field indentSyntax should only be used after it is initialized.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions