Skip to content

Add error message - Parsers.scala:695 #1628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ object Parsers {
else {
for (t <- ts)
if (t.isInstanceOf[ByNameTypeTree])
syntaxError("no by-name parameter type allowed here", t.pos)
syntaxError(ByNameParameterNotSupported())
val tuple = atPos(start) { makeTupleOrParens(ts) }
infixTypeRest(refinedTypeRest(withTypeRest(simpleTypeRest(tuple))))
}
Expand Down
24 changes: 24 additions & 0 deletions src/dotty/tools/dotc/reporting/diagnostic/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -581,4 +581,28 @@ object messages {
}
}


case class ByNameParameterNotSupported()(implicit ctx: Context) extends Message(21) {
val kind = "Syntax"

val msg = "By-name parameter type not allowed here."

val explanation =
hl"""|By-name parameters act like functions that are only evaluated when referenced,
|allowing for lazy evaluation of a parameter.
|
|An example of using a by-name parameter would look like:
|${"def func(f: => Boolean) = f // 'f' is evaluated when referenced within the function"}
|
|An example of the syntax of passing an actual function as a parameter:
|${"def func(f: (Boolean => Boolean)) = f(true)"}
|
|or:
|
|${"def func(f: Boolean => Boolean) = f(true)"}
|
|And the usage could be as such:
|${"func(bool => // do something...)"}
|""".stripMargin
}
}