Skip to content

Commit fc3c6a6

Browse files
committed
Add error message - Parsers.scala:695
1 parent f57086d commit fc3c6a6

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ object Parsers {
692692
else {
693693
for (t <- ts)
694694
if (t.isInstanceOf[ByNameTypeTree])
695-
syntaxError("no by-name parameter type allowed here", t.pos)
695+
syntaxError(ByNameParameterNotSupported())
696696
val tuple = atPos(start) { makeTupleOrParens(ts) }
697697
infixTypeRest(refinedTypeRest(withTypeRest(simpleTypeRest(tuple))))
698698
}

src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,4 +581,28 @@ object messages {
581581
}
582582
}
583583

584+
585+
case class ByNameParameterNotSupported()(implicit ctx: Context) extends Message(21) {
586+
val kind = "Syntax"
587+
588+
val msg = "By-name parameter type not allowed here."
589+
590+
val explanation =
591+
hl"""|By-name parameters act like functions that are only evaluated when referenced,
592+
|allowing for lazy evaluation of a parameter.
593+
|
594+
|An example of using a by-name parameter would look like:
595+
|${"def func(f: => Boolean) = f // 'f' is evaluated when referenced within the function"}
596+
|
597+
|An example of the syntax of passing an actual function as a parameter:
598+
|${"def func(f: (Boolean => Boolean)) = f(true)"}
599+
|
600+
|or:
601+
|
602+
|${"def func(f: Boolean => Boolean) = f(true)"}
603+
|
604+
|And the usage could be as such:
605+
|${"func(bool => // do something...)"}
606+
|""".stripMargin
607+
}
584608
}

0 commit comments

Comments
 (0)