diff options
author | Paul Phillips <paulp@improving.org> | 2010-11-26 23:53:26 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-11-26 23:53:26 +0000 |
commit | 72d12aabf35f699ef103d79f29f8f7b21286d94c (patch) | |
tree | d2010d12e1dcc9705a9c7ff3b1005e728c04cc16 | |
parent | 5be89bb3bf95f9a11773273fee5d692e4a9a7f03 (diff) | |
download | scala-72d12aabf35f699ef103d79f29f8f7b21286d94c.tar.gz scala-72d12aabf35f699ef103d79f29f8f7b21286d94c.tar.bz2 scala-72d12aabf35f699ef103d79f29f8f7b21286d94c.zip |
Some work on error messages, somewhat based on ...
Some work on error messages, somewhat based on ideas in #3092. No
review.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala | 30 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 17 | ||||
-rw-r--r-- | test/files/neg/predef-masking.check | 4 | ||||
-rw-r--r-- | test/files/neg/predef-masking.scala | 21 | ||||
-rw-r--r-- | test/files/neg/type-diagnostics.check | 6 | ||||
-rw-r--r-- | test/files/neg/type-diagnostics.scala | 4 | ||||
-rw-r--r-- | test/pending/neg/type-diagnostics.scala | 11 |
7 files changed, 72 insertions, 21 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index 081be78c8b..99c85f72f1 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -145,11 +145,15 @@ trait TypeDiagnostics { def alternativesString(tree: Tree) = alternatives(tree) map (x => " " + methodTypeErrorString(x)) mkString ("", " <and>\n", "\n") - def missingParameterTypeError(fun: Tree, vparam: ValDef) = { - val suffix = if (vparam.mods.isSynthetic) " for expanded function "+fun else "" - - inferError(vparam.pos, "missing parameter type" + suffix) - ErrorType + def missingParameterTypeMsg(fun: Tree, vparam: ValDef) = { + val suffix = + if (!vparam.mods.isSynthetic) "" + else " for expanded function" + (fun match { + case Function(_, Match(_, _)) => "\n(see SLS 8.5, \"Pattern Matching Anonymous Functions\")" + case _ => " " + fun + }) + + "missing parameter type" + suffix } def treeSymTypeMsg(tree: Tree): String = { @@ -170,6 +174,22 @@ trait TypeDiagnostics { else defaultMessage } + def notEnoughArgumentsMsg(fun: Tree, missing: List[Symbol]): String = { + val suffix = { + if (missing.isEmpty) "" + else { + val keep = missing take 3 map (_.name) + ".\nUnspecified value parameter%s %s".format( + if (missing.tail.isEmpty) "" else "s", + if (missing drop 3 nonEmpty) (keep :+ "...").mkString(", ") + else keep.mkString("", ", ", ".") + ) + } + } + + "not enough arguments for " + treeSymTypeMsg(fun) + suffix + } + def applyErrorMsg(tree: Tree, msg: String, argtpes: List[Type], pt: Type) = { def asParams(xs: List[Any]) = xs.mkString("(", ", ", ")") diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 0ead1f6eee..155883299a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2036,11 +2036,7 @@ trait Typers { self: Analyzer => } case _ => } - error( - vparam.pos, - "missing parameter type"+ - (if (vparam.mods.isSynthetic) " for expanded function "+fun - else "")) + error(vparam.pos, missingParameterTypeMsg(fun, vparam)) ErrorType } if (!vparam.tpt.pos.isDefined) vparam.tpt setPos vparam.pos.focus @@ -2390,16 +2386,7 @@ trait Typers { self: Analyzer => if (!(context.diagnostic contains note)) context.diagnostic = note :: context.diagnostic doTypedApply(tree, if (blockIsEmpty) fun else fun1, allArgs, mode, pt) } else { - tryTupleApply.getOrElse { - val suffix = - if (missing.isEmpty) "" - else { - val missingStr = missing.take(3).map(_.name).mkString(", ") + (if (missing.length > 3) ", ..." else ".") - val sOpt = if (missing.length > 1) "s" else "" - ".\nUnspecified value parameter"+ sOpt +" "+ missingStr - } - errorTree(tree, "not enough arguments for "+treeSymTypeMsg(fun) + suffix) - } + tryTupleApply getOrElse errorTree(tree, notEnoughArgumentsMsg(fun, missing)) } } } diff --git a/test/files/neg/predef-masking.check b/test/files/neg/predef-masking.check new file mode 100644 index 0000000000..79e4dece8a --- /dev/null +++ b/test/files/neg/predef-masking.check @@ -0,0 +1,4 @@ +predef-masking.scala:7: error: value + is not a member of type parameter T + def f[T](x: T) = x + 5 + ^ +one error found diff --git a/test/files/neg/predef-masking.scala b/test/files/neg/predef-masking.scala new file mode 100644 index 0000000000..67b69aa169 --- /dev/null +++ b/test/files/neg/predef-masking.scala @@ -0,0 +1,21 @@ +// Testing predef masking +import Predef.{ any2stringadd => _, _ } + +object StringPlusConfusion { + // Would love to do something about this error message, but by the + // time we get our hands on it the context is lost. + def f[T](x: T) = x + 5 + + // After we block out any2stringadd, the error is: + // + // work/a.scala:7: error: value + is not a member of type parameter T + // def f[T](x: T) = x + 5 + // ^ + // Normally, it is: + // + // work/a.scala:7: error: type mismatch; + // found : Int(5) + // required: String + // def f[T](x: T) = x + 5 + // ^ +} diff --git a/test/files/neg/type-diagnostics.check b/test/files/neg/type-diagnostics.check index 33e07f3816..62d580a788 100644 --- a/test/files/neg/type-diagnostics.check +++ b/test/files/neg/type-diagnostics.check @@ -13,4 +13,8 @@ type-diagnostics.scala:17: error: type mismatch; required: java.lang.String def f2[String](s: String) = strings(List(s)) ^ -three errors found +type-diagnostics.scala:21: error: missing parameter type for expanded function +(see SLS 8.5, "Pattern Matching Anonymous Functions") + val f = { case 5 => 10 } + ^ +four errors found diff --git a/test/files/neg/type-diagnostics.scala b/test/files/neg/type-diagnostics.scala index fdc0978138..fcc49812f4 100644 --- a/test/files/neg/type-diagnostics.scala +++ b/test/files/neg/type-diagnostics.scala @@ -16,3 +16,7 @@ object TParamConfusion { def f2[String](s: String) = strings(List(s)) } + +object PartialInfer { + val f = { case 5 => 10 } +}
\ No newline at end of file diff --git a/test/pending/neg/type-diagnostics.scala b/test/pending/neg/type-diagnostics.scala new file mode 100644 index 0000000000..7f9a151dcd --- /dev/null +++ b/test/pending/neg/type-diagnostics.scala @@ -0,0 +1,11 @@ +object TooManyParens { + def f = Map(1 -> 2).keySet() + // + // Confusion reigns! + // + // work/a.scala:27: error: not enough arguments for method apply: (elem: Int)Boolean in trait SetLike. + // Unspecified value parameter elem. + // def f = Map(1 -> 2).keySet() + // ^ + +} |