diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 1fee0f52f770..32d60d84bb6d 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -265,7 +265,7 @@ object Scanners { val next = newTokenData private val prev = newTokenData - /** The current region. This is initially an Indented region with indentation width. */ + /** The current region. This is initially an Indented region with zero indentation width. */ var currentRegion: Region = Indented(IndentWidth.Zero, Set(), EMPTY, null) // Get next token ------------------------------------------------------------ @@ -434,8 +434,8 @@ object Scanners { && !migrateTo3 && !noindentSyntax - /** The indentation width of the given offset */ - def indentWidth(offset: Offset): IndentWidth = { + /** The indentation width of the given offset. */ + def indentWidth(offset: Offset): IndentWidth = import IndentWidth.{Run, Conc} def recur(idx: Int, ch: Char, n: Int, k: IndentWidth => IndentWidth): IndentWidth = if (idx < 0) k(Run(ch, n)) @@ -452,7 +452,7 @@ object Scanners { else recur(idx - 1, ' ', 0, identity) } recur(offset - 1, ' ', 0, identity) - } + end indentWidth /** Handle newlines, possibly inserting an INDENT, OUTDENT, NEWLINE, or NEWLINES token * in front of the current token. This depends on whether indentation is significant or not. @@ -521,6 +521,7 @@ object Scanners { lastWidth = r.width newlineIsSeparating = lastWidth <= nextWidth || r.isOutermost indentPrefix = r.prefix + case _: InString => () case r => indentIsSignificant = indentSyntax r.proposeKnownWidth(nextWidth, lastToken) @@ -1424,7 +1425,7 @@ object Scanners { nextToken() currentRegion = topLevelRegion(indentWidth(offset)) } - // end Scanner + end Scanner /** A Region indicates what encloses the current token. It can be one of the following * diff --git a/tests/neg/i14386.scala b/tests/neg/i14386.scala new file mode 100644 index 000000000000..c25b6ba9f3c1 --- /dev/null +++ b/tests/neg/i14386.scala @@ -0,0 +1,48 @@ +// scalac: -Werror +def logLevelDetail(level: Int): String = + s"""$level + +// the following line is indented using [tab][tab] + Sets the global logging level to $level. + """ + /* was 2 errors with carets as shown + | ^ ^ + | Incompatible combinations of tabs and spaces in indentation prefixes. + | Previous indent : 3 spaces + | Latest indent : 2 tabs + */ + +def log(level: Int, msg: String): String = + s""" + $level + prefixed $level suffixed + """ +/* + ^ ^ + Incompatible combinations of tabs and spaces in indentation prefixes. + Previous indent : 2 tabs + Latest indent : 2 space + */ + +// normal mixed tabs errors as a baseline +def g = + 42 + + 17 // error + +def p() = + println("hello") + println("world") // error + /* + | Incompatible combinations of tabs and spaces in indentation prefixes. + | Previous indent : 4 spaces + | Latest indent : 1 tab + */ + +def braced() = + s"""begin + ${ + val level = 10 + val msg = "hello, world" // error he lets me off with a warning + log(level, msg) // error + } + end"""