diff options
author | Paul Phillips <paulp@improving.org> | 2013-04-30 16:13:42 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-04-30 16:13:42 -0700 |
commit | 13cf0481d2f584e464216b59eb73e33881d91bc6 (patch) | |
tree | 873306aeb2fafe355f8d977eefb28480ff56b3fe /src | |
parent | 947e51f13f6811c1254f6084a20f9a59829adc20 (diff) | |
parent | 12dd8c02bbb71233f7b8ab9b2cbf8e84cda2080d (diff) | |
download | scala-13cf0481d2f584e464216b59eb73e33881d91bc6.tar.gz scala-13cf0481d2f584e464216b59eb73e33881d91bc6.tar.bz2 scala-13cf0481d2f584e464216b59eb73e33881d91bc6.zip |
Merge pull request #2406 from paulp/issue/7362
SI-7362, crash in presentation compiler
Diffstat (limited to 'src')
3 files changed, 17 insertions, 19 deletions
diff --git a/src/interactive/scala/tools/nsc/interactive/CompilerControl.scala b/src/interactive/scala/tools/nsc/interactive/CompilerControl.scala index b4d3fd8aa0..c38c7c8257 100644 --- a/src/interactive/scala/tools/nsc/interactive/CompilerControl.scala +++ b/src/interactive/scala/tools/nsc/interactive/CompilerControl.scala @@ -295,6 +295,9 @@ trait CompilerControl { self: Global => val tpe: Type val accessible: Boolean def implicitlyAdded = false + + private def accessible_s = if (accessible) "" else "[inaccessible] " + def infoString = s"$accessible_s${sym.defStringSeenAs(tpe)}" } case class TypeMember( diff --git a/src/interactive/scala/tools/nsc/interactive/Global.scala b/src/interactive/scala/tools/nsc/interactive/Global.scala index 792ca6efa6..b6f4779bc4 100644 --- a/src/interactive/scala/tools/nsc/interactive/Global.scala +++ b/src/interactive/scala/tools/nsc/interactive/Global.scala @@ -1033,23 +1033,21 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "") } private def typeMembers(pos: Position): Stream[List[TypeMember]] = { - var tree = typedTreeAt(pos) - - // if tree consists of just x. or x.fo where fo is not yet a full member name - // ignore the selection and look in just x. - tree match { - case Select(qual, name) if tree.tpe == ErrorType => tree = qual - case _ => + // Choosing which tree will tell us the type members at the given position: + // If pos leads to an Import, type the expr + // If pos leads to a Select, type the qualifier as long as it is not erroneous + // (this implies discarding the possibly incomplete name in the Select node) + // Otherwise, type the tree found at 'pos' directly. + val tree0 = typedTreeAt(pos) match { + case sel @ Select(qual, _) if sel.tpe == ErrorType => qual + case Import(expr, _) => expr + case t => t } - val context = doLocateContext(pos) - - if (tree.tpe == null) - // TODO: guard with try/catch to deal with ill-typed qualifiers. - tree = analyzer.newTyper(context).typedQualifier(tree) + // TODO: guard with try/catch to deal with ill-typed qualifiers. + val tree = if (tree0.tpe eq null) analyzer newTyper context typedQualifier tree0 else tree0 debugLog("typeMembers at "+tree+" "+tree.tpe) - val superAccess = tree.isInstanceOf[Super] val members = new Members[TypeMember] diff --git a/src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala b/src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala index c0ad245091..08d84af8f5 100644 --- a/src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala +++ b/src/interactive/scala/tools/nsc/interactive/tests/core/CoreTestDefs.scala @@ -16,21 +16,18 @@ private[tests] trait CoreTestDefs extends PresentationCompilerTestDef with AskCompletionAt { - def memberPrinter(member: compiler.Member): String = - "[accessible: %5s] ".format(member.accessible) + "`" + (member.sym.toString.trim + member.tpe.toString()).trim + "`" - override def runTest() { askAllSources(CompletionMarker) { pos => askCompletionAt(pos) } { (pos, members) => withResponseDelimiter { - reporter.println("[response] aksTypeCompletion at " + format(pos)) + reporter.println("[response] askCompletionAt " + format(pos)) // we skip getClass because it changed signature between 1.5 and 1.6, so there is no // universal check file that we can provide for this to work reporter.println("retrieved %d members".format(members.size)) compiler ask { () => val filtered = members.filterNot(member => (member.sym.name string_== "getClass") || member.sym.isConstructor) - reporter.println(filtered.map(memberPrinter).sortBy(_.toString()).mkString("\n")) + reporter println (filtered.map(_.infoString).sorted mkString "\n") } } } @@ -48,7 +45,7 @@ private[tests] trait CoreTestDefs askTypeAt(pos) } { (pos, tree) => withResponseDelimiter { - reporter.println("[response] askTypeAt at " + format(pos)) + reporter.println("[response] askTypeAt " + format(pos)) compiler.ask(() => reporter.println(tree)) } } |