Skip to content

Commit

Permalink
bugfix: Fix StacktraceAnalyser in case of empty package
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Dec 29, 2023
1 parent 510386d commit ccd13ba
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ object StacktraceAnalyzer {
/* Symbol containing `$package$` is a toplevel method and we only need to
* find any method contained in the same file even if overloaded
*/
if (symbol.contains("$package$")) {
val symbolToFind = if (symbol.contains("$package$")) {
symbolIn.split("\\$package\\$") match {
case Array(filePath, symbol) =>
val re = filePath.replace('.', '/') + "$package" + symbol
Expand All @@ -232,6 +232,11 @@ object StacktraceAnalyzer {
} else {
List(symbol :+ '#')
}
symbolToFind.map {
// empty package needs to be added if no package is present
case sym if !sym.contains("/") => "_empty_/" + sym
case sym => sym
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,49 @@ class CrossAnalyzeStacktraceSuite
scalaVersion = V.scala3,
)

check(
"no-package",
"""|
|def fetch() =
| println("Fetching!")
|<<1>> throw new Exception("")
|
|@main
|def main() =
|<<2>> fetch()
|
|def fetch(a: Int) = a + 2
|""".stripMargin,
"""|Exception in thread "main" java.lang.Exception:
|at other$package$.fetch(other.scala:4)
|at other$package$.main(other.scala:8)
|at main.main(other.scala:6)
|""".stripMargin,
filename = "other.scala",
scalaVersion = V.scala3,
)

check(
"no-package-type",
"""|
|
|object O:
| def fetch() =
| println("Fetching!")
|<<1>> throw new Exception("")
|
|@main
|def main() =
|<<2>> fetch()
|
|def fetch(a: Int) = a + 2
|""".stripMargin,
"""|Exception in thread "main" java.lang.Exception:
|at O$.fetch(Main.scala:6)
|at other$package$.main(other.scala:10)
|at main.main(other.scala:8)
|""".stripMargin,
filename = "other.scala",
scalaVersion = V.scala3,
)
}

0 comments on commit ccd13ba

Please sign in to comment.