aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/reporting
diff options
context:
space:
mode:
authorShane Delmore <shane@delmore.io>2016-10-24 17:34:37 -0700
committerShane Delmore <shane@delmore.io>2016-10-25 14:37:00 -0700
commit63f1a3c5d0149d173eb8f65405b5983591752229 (patch)
treef12825d3305e9752654de33ff2714695315edf42 /src/dotty/tools/dotc/reporting
parent0ab12174a5a60616a0ef818a86b21adeb21395bb (diff)
downloaddotty-63f1a3c5d0149d173eb8f65405b5983591752229.tar.gz
dotty-63f1a3c5d0149d173eb8f65405b5983591752229.tar.bz2
dotty-63f1a3c5d0149d173eb8f65405b5983591752229.zip
Improve error message for WrongNumberOfArgs
Diffstat (limited to 'src/dotty/tools/dotc/reporting')
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/messages.scala35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index f76512bc7..57d96224a 100644
--- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -10,6 +10,7 @@ import util.{SourceFile, NoSource}
import util.{SourcePosition, NoSourcePosition}
import config.Settings.Setting
import interfaces.Diagnostic.{ERROR, WARNING, INFO}
+import dotty.tools.dotc.ast.tpd
import printing.Highlighting._
import printing.Formatting
@@ -605,4 +606,38 @@ object messages {
|${"func(bool => // do something...)"}
|""".stripMargin
}
+ case class WrongNumberOfArgs(fntpe: Type, argKind: String, expectedArgs: List[TypeParamInfo], actual: List[untpd.Tree])(implicit ctx: Context)
+ extends Message(18) {
+ val kind = "Syntax"
+ val expectedCount = expectedArgs.length
+ val actualCount = actual.length
+ val msgPrefix = if (actualCount > expectedCount) "Too many" else "Not enough"
+
+ val expectedArgString = (fntpe.widen match {
+ case pt: MethodOrPoly => pt //ensure we return a type that will have useful typeParms
+ case _ => fntpe
+ }).typeParams.map(_.paramName.show.split("\\$").last).mkString("[", ", ", "]")
+
+ val actualArgString = actual.map(_.show.split("\\.").last).mkString("[", ", ", "]")
+
+ val msg =
+ hl"""|$msgPrefix ${argKind} arguments for $fntpe
+ |expected: $expectedArgString
+ |actual: $actualArgString""".stripMargin
+
+ val explanation = {
+ if (actualCount > expectedCount)
+ hl"""|You have supplied too many type parameters
+ |
+ |For example List takes a single type parameter (List[A])
+ | If you need to hold more types in a list then you need to combine them
+ | into another data type that can contain the number of types you need,
+ | In this example one solution would be to use a Tuple:
+ | val tuple2: Tuple2[Int, String = (1, "one)
+ | List[(Int, String)] = List(tuple2)""".stripMargin
+ else
+ hl"""|You have not supplied enough type parameters
+ | If you specify one type parameter then you need to specify every type parameter.""".stripMargin
+ }
+ }
}