From cf4037a46ca3aabcff8e444d6814f5a91d023d4b Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 2 Aug 2011 06:50:28 +0000 Subject: Made error messages like "object List is not a ... Made error messages like "object List is not a value" be a little more helpful about why that is. No review. --- src/compiler/scala/reflect/internal/TypeDebugging.scala | 11 +++++++---- src/compiler/scala/tools/nsc/typechecker/Implicits.scala | 4 +++- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 6 ++++-- 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/reflect/internal/TypeDebugging.scala b/src/compiler/scala/reflect/internal/TypeDebugging.scala index d56e2e1991..54efef8142 100644 --- a/src/compiler/scala/reflect/internal/TypeDebugging.scala +++ b/src/compiler/scala/reflect/internal/TypeDebugging.scala @@ -22,11 +22,14 @@ trait TypeDebugging { } def ptIndent(x: Any) = ("" + x).replaceAll("\\n", " ") def ptBlock(label: String, pairs: (String, Any)*): String = { - val width = pairs map (_._1.length) max - val fmt = "%-" + (width + 1) + "s %s" - val strs = pairs map { case (k, v) => fmt.format(k, to_s(v)) } + if (pairs.isEmpty) label + "{ }" + else { + val width = pairs map (_._1.length) max + val fmt = "%-" + (width + 1) + "s %s" + val strs = pairs map { case (k, v) => fmt.format(k, to_s(v)) } - strs.mkString(label + " {\n ", "\n ", "\n}") + strs.mkString(label + " {\n ", "\n ", "\n}") + } } def ptLine(label: String, pairs: (String, Any)*): String = { val strs = pairs map { case (k, v) => k + "=" + to_s(v) } diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 097bbf5915..169295e5c9 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -935,7 +935,9 @@ trait Implicits { val infoMap = new InfoMap getParts(tp)(infoMap, new mutable.HashSet(), Set()) - printInference("[companionImplicitMap] "+tp+" = "+infoMap) + printInference( + ptBlock("companionImplicitMap " + tp, infoMap.toSeq.map({ case (k, v) => ("" + k, v.mkString(", ")) }): _*) + ) infoMap } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 0385cfee63..e0639cb6cf 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -558,14 +558,16 @@ trait Typers extends Modes with Adaptations { private def stabilize(tree: Tree, pre: Type, mode: Int, pt: Type): Tree = { if (tree.symbol.isOverloaded && !inFunMode(mode)) inferExprAlternative(tree, pt) + val sym = tree.symbol + def fail() = errorTree(tree, sym.kindString + " " + sym.fullName + " is not a value") if (tree.tpe.isError) tree else if ((mode & (PATTERNmode | FUNmode)) == PATTERNmode && tree.isTerm) { // (1) if (sym.isValue) checkStable(tree) - else errorTree(tree, sym+" is not a value") + else fail() } else if ((mode & (EXPRmode | QUALmode)) == EXPRmode && !sym.isValue && !phase.erasedTypes) { // (2) - errorTree(tree, sym+" is not a value") + fail() } else { if (sym.isStable && pre.isStable && !isByNameParamType(tree.tpe) && (isStableContext(tree, mode, pt) || sym.isModule && !sym.isMethod)) -- cgit v1.2.3