From 231d59dcf57af99a9e2a1366afd18680c13cd6ce Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 22 Dec 2012 10:12:03 -0800 Subject: SI-6829, SI-6788, NPEs during erroneous compilation. Have to intercept trees which have a null type due to errors before they leave the warm confines of 'def typed' because from that point everything assumes tree.tpe != null. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index e45d64ade5..9d390476db 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -5264,7 +5264,7 @@ trait Typers extends Modes with Adaptations with Tags { def typedDocDef(docdef: DocDef) = { if (forScaladoc && (sym ne null) && (sym ne NoSymbol)) { - val comment = docdef.comment + val comment = docdef.comment docComments(sym) = comment comment.defineVariables(sym) val typer1 = newTyper(context.makeNewScope(tree, context.owner)) @@ -5595,12 +5595,18 @@ trait Typers extends Modes with Adaptations with Tags { "context.owner" -> context.owner ) ) - val tree1 = typed1(tree, mode, dropExistential(pt)) + typed1(tree, mode, dropExistential(pt)) + } + // Can happen during erroneous compilation - error(s) have been + // reported, but we need to avoid causing an NPE with this tree + if (tree1.tpe eq null) + return setError(tree) + + if (!alreadyTyped) { printTyping("typed %s: %s%s".format( ptTree(tree1), tree1.tpe, if (isSingleType(tree1.tpe)) " with underlying "+tree1.tpe.widen else "") ) - tree1 } tree1.tpe = addAnnotations(tree1, tree1.tpe) -- cgit v1.2.3