From 5f50e0368e635db8279797095dbd34470722d5c7 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sat, 8 Nov 2014 22:50:47 +1000 Subject: SI-8534 Avoid crash in erroneous SelectFromTypeTree PR #2374 changed the behaviour of `typedSingletonTypeTree` in the presence of an error typed reference tree. It incorrectly returns the reference tree in case on an error. However, this is a term tree, which is an inconsistent result with the input type tree. Consequently, a `typedSelectInternal` later fails when using this as the qualifier of a `SelectFromTypeTree`. Both test cases enclosed show this symptom. This commit: - Returns `tree` rather than `refTyped` when `refTyped` is error typed or when it isn't suitable as a stable prefix. - Avoids issuing a cascading "not a stable prefix" error if the `refTyped` is error typed. - Adds an extra layer of defense in `typedSelectFromTypeTree` to bail out quickly if the qualifier is error typed. The last measure is not necessary to fix this bug. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 70acb03584..64fbad04c0 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -5134,16 +5134,19 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper typed(tree.ref, MonoQualifierModes | mode.onlyTypePat, AnyRefTpe) } - if (!refTyped.isErrorTyped) + if (refTyped.isErrorTyped) { + setError(tree) + } else { tree setType refTyped.tpe.resultType - - if (treeInfo.admitsTypeSelection(refTyped)) tree - else UnstableTreeError(refTyped) + if (refTyped.isErrorTyped || treeInfo.admitsTypeSelection(refTyped)) tree + else UnstableTreeError(tree) + } } def typedSelectFromTypeTree(tree: SelectFromTypeTree) = { val qual1 = typedType(tree.qualifier, mode) - if (qual1.tpe.isVolatile) TypeSelectionFromVolatileTypeError(tree, qual1) + if (qual1.isErrorTyped) setError(treeCopy.SelectFromTypeTree(tree, qual1, tree.name)) + else if (qual1.tpe.isVolatile) TypeSelectionFromVolatileTypeError(tree, qual1) else typedSelect(tree, qual1, tree.name) } -- cgit v1.2.3