null-robustness for presentation test

ran into NPEs while running the test suite using the virtpatmat compiler,
decided it might happen to others
thus undertook to shield said others from sad NPEs

no review

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@26007 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
moors 2011-11-14 16:28:45 +00:00
parent 54c69f64b6
commit 4cacaaab1b
1 changed files with 6 additions and 2 deletions

View File

@ -81,7 +81,11 @@ private[tests] trait CoreTestDefs
else {
reporter.println("\naskHyperlinkPos for `" + tree.symbol.name + "` at " + format(pos) + " " + pos.source.file.name)
val r = new Response[Position]
val sourceFile = sourceFiles.find(tree.symbol.sourceFile.path == _.path) match {
// `tree.symbol.sourceFile` was discovered to be null when testing -Yvirtpatmat on the akka presentation test, where a position had shifted to point to `Int`
// askHyperlinkPos for `Int` at (73,19) pi.scala --> class Int in package scala has null sourceFile!
val treePath = if (tree.symbol.sourceFile ne null) tree.symbol.sourceFile.path else null
val treeName = if (tree.symbol.sourceFile ne null) tree.symbol.sourceFile.name else null
val sourceFile = sourceFiles.find(_.path == treePath) match {
case Some(source) =>
compiler.askLinkPos(tree.symbol, source, r)
r.get match {
@ -93,7 +97,7 @@ private[tests] trait CoreTestDefs
ex.printStackTrace()
}
case None =>
reporter.println("[error] could not locate sourcefile `" + tree.symbol.sourceFile.name + "`." +
reporter.println("[error] could not locate sourcefile `" + treeName + "`." +
"Hint: Does the looked up definition come form a binary?")
}
}