Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix line numbers in errors for scripts starting with leading comments or whitespace #2686

Merged
merged 4 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/basic/2-custom-build-logic/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Line Count: 11
11

> ./mill inspect lineCount
lineCount(build.sc:7)
lineCount(build.sc:12)
Total number of lines in module's source files
Inputs:
allSourceFiles
Expand Down
13 changes: 13 additions & 0 deletions integration/failure/compile-error/repo/bar.sc
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Make sure this
/* gives the correct */
// line numbers
import scala._

def myScalaVersion = "2.13.8"
// when there
// are a bunch

/**
* Of comments and imports
*/

println(doesntExist)

// Scattered throughout
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object CompileErrorTests extends IntegrationTestSuite {
val res = evalStdout("foo.scalaVersion")

assert(res.isSuccess == false)
assert(res.err.contains("""bar.sc:3:9: not found: value doesntExist"""))
assert(res.err.contains("""bar.sc:14:9: not found: value doesntExist"""))
assert(res.err.contains("""println(doesntExist)"""))
assert(res.err.contains("""qux.sc:3:34: type mismatch;"""))
assert(res.err.contains(
Expand Down
14 changes: 13 additions & 1 deletion integration/failure/parse-error/repo/bar.sc
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
// Make sure this
/* gives the correct */
// line numbers
import scala._

def myScalaVersion = "2.13.8"
// when there
// are a bunch

/**
* Of comments and imports
*/

println(doesntExist})

println(doesntExist})
// Scattered throughout
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object ParseErrorTests extends IntegrationTestSuite {

assert(res.isSuccess == false)

assert(res.err.contains("""bar.sc:4:20 expected ")""""))
assert(res.err.contains("""bar.sc:14:20 expected ")""""))
assert(res.err.contains("""println(doesntExist})"""))
assert(res.err.contains("""qux.sc:3:31 expected ")""""))
assert(res.err.contains("""System.out.println(doesntExist"""))
Expand Down
3 changes: 3 additions & 0 deletions readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ _Changes since {prev-version}:_
analysis to see which targets depend on the code that was changed. See
https://github.com/com-lihaoyi/mill/pull/2417[#2417] for more details

* Fix line numbers in errors for scripts starting with leading comments or
whitespace https://github.com/com-lihaoyi/mill/pull/2686[#2686]

_For details refer to
{link-milestone}/{milestone}?closed=1[milestone {milestone-name}]
and the {link-compare}/{prev-version}\...{version}[list of commits]._
Expand Down
11 changes: 1 addition & 10 deletions runner/src/mill/runner/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,8 @@ object Parsers {
def StatementBlock[$: P] =
P(Semis.? ~ (TmplStat ~~ WS ~~ (Semis | &("}") | End)).!.repX)

def CompilationUnit[$: P] = P(HashBang.!.? ~ WL.! ~ StatementBlock ~ WL ~ End)
def CompilationUnit[$: P] = P(HashBang.!.? ~~ WL.! ~~ StatementBlock ~ WL ~ End)

def stringWrap(s: String): String = "\"" + pprint.Util.literalize(s) + "\""
def stringSymWrap(s: String): String = {
def idToEnd[$: P] = P(scalaparse.syntax.Identifiers.Id ~ End)
if (s == "") "'"
else parse(s, idToEnd(_)) match {
case Parsed.Success(v, _) => "'" + s
case f: Parsed.Failure => stringWrap(s)
}
}
def parseImportHooksWithIndices(stmts: Seq[String]): Seq[(String, Seq[ImportTree])] = {
val hookedStmts = mutable.Buffer.empty[(String, Seq[ImportTree])]
for (stmt <- stmts) {
Expand Down