From dc3fdb0d493a7aa8b5a8905b92248275471b7b74 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Mon, 14 Nov 2011 16:28:45 +0000 Subject: 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 --- .../scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala b/src/compiler/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala index 0ca52dcba7..40bbd3fa8e 100644 --- a/src/compiler/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala +++ b/src/compiler/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala @@ -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?") } } -- cgit v1.2.3