diff options
author | Som Snytt <som.snytt@gmail.com> | 2015-06-26 21:32:29 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2015-06-27 01:55:45 -0700 |
commit | 96b012aa48e3d91f8ec6d5221df2f455f278c9e0 (patch) | |
tree | e78a49eeeb01ca4a516385d316062b6b83358ee3 /src/compiler | |
parent | 5b8073676cc77c2c889ed690f12bb6a99e790769 (diff) | |
download | scala-96b012aa48e3d91f8ec6d5221df2f455f278c9e0.tar.gz scala-96b012aa48e3d91f8ec6d5221df2f455f278c9e0.tar.bz2 scala-96b012aa48e3d91f8ec6d5221df2f455f278c9e0.zip |
Improved message for missing argument list
Clarifies the language and rules for eta-expansion.
A missing argument in a list, as opposed to a missing
argument list, results in a different message.
The comical expansion in parens does not attempt to show
what was already applied, but succeeds in showing at a
glance the shape of the method in question.
```
scala> def m(i: Int, j: Int)(x: Int) = ???
m: (i: Int, j: Int)(x: Int)Nothing
scala> m
<console>:12: error: missing argument list for method m
Unapplied methods are only converted to functions when a function type is expected.
You can make this conversion explicit by writing `m _` or `m(_,_)(_)` instead of `m`.
m
^
```
The original submission was due to sschaef and the wording due
to adriaanm, with a minor tweak.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala index c80aaea160..b0bd9977a8 100644 --- a/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala @@ -550,23 +550,18 @@ trait ContextErrors { def ModuleUsingCompanionClassDefaultArgsErrror(tree: Tree) = NormalTypeError(tree, "module extending its companion class cannot use default constructor arguments") - def NotEnoughArgsError(tree: Tree, fun0: Tree, missing0: List[Symbol]) = { - def notEnoughArgumentsMsg(fun: Tree, missing: List[Symbol]) = { - 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("", ", ", ".") - ) - } + def NotEnoughArgsError(tree: Tree, fun: Tree, missing: List[Symbol]) = { + val notEnoughArgumentsMsg = { + val suffix = if (missing.isEmpty) "" else { + val keep = missing take 3 map (_.name) + val ess = if (missing.tail.isEmpty) "" else "s" + f".%nUnspecified value parameter$ess ${ + keep.mkString("", ", ", if ((missing drop 3).nonEmpty) "..." else ".") + }" } - - "not enough arguments for " + treeSymTypeMsg(fun) + suffix + s"not enough arguments for ${ treeSymTypeMsg(fun) }$suffix" } - NormalTypeError(tree, notEnoughArgumentsMsg(fun0, missing0)) + NormalTypeError(tree, notEnoughArgumentsMsg) } //doTypedApply - patternMode @@ -632,12 +627,16 @@ trait ContextErrors { //adapt def MissingArgsForMethodTpeError(tree: Tree, meth: Symbol) = { + val f = meth.name + val paf = s"$f(${ meth.asMethod.paramLists map (_ map (_ => "_") mkString ",") mkString ")(" })" + val advice = s""" + |Unapplied methods are only converted to functions when a function type is expected. + |You can make this conversion explicit by writing `$f _` or `$paf` instead of `$f`.""".stripMargin val message = if (meth.isMacro) MacroTooFewArgumentListsMessage - else "missing arguments for " + meth.fullLocationString + ( - if (meth.isConstructor) "" - else ";\nfollow this method with `_' if you want to treat it as a partially applied function" - ) + else s"""missing argument list for ${meth.fullLocationString}${ + if (!meth.isConstructor) advice else "" + }""" issueNormalTypeError(tree, message) setError(tree) } |