File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -692,7 +692,7 @@ object Parsers {
692
692
else {
693
693
for (t <- ts)
694
694
if (t.isInstanceOf [ByNameTypeTree ])
695
- syntaxError(" no by-name parameter type allowed here " , t.pos )
695
+ syntaxError(ByNameParameterNotSupported () )
696
696
val tuple = atPos(start) { makeTupleOrParens(ts) }
697
697
infixTypeRest(refinedTypeRest(withTypeRest(simpleTypeRest(tuple))))
698
698
}
Original file line number Diff line number Diff line change @@ -581,4 +581,28 @@ object messages {
581
581
}
582
582
}
583
583
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
+ }
584
608
}
You can’t perform that action at this time.
0 commit comments