File tree 2 files changed +36
-1
lines changed
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -334,7 +334,7 @@ object Parsers {
334
334
try op
335
335
finally {
336
336
placeholderParams match {
337
- case vd :: _ => syntaxError(" unbound placeholder parameter " , vd.pos)
337
+ case vd :: _ => syntaxError(UnboundPlaceholderParameter () , vd.pos)
338
338
case _ =>
339
339
}
340
340
placeholderParams = savedPlaceholderParams
Original file line number Diff line number Diff line change @@ -447,4 +447,39 @@ object messages {
447
447
448
448
}
449
449
450
+ case class UnboundPlaceholderParameter ()(implicit ctx: Context )
451
+ extends Message (16 ) {
452
+ val kind = " Syntax"
453
+
454
+ val msg = hl " unbound placeholder parameter; incorrect use of `_` "
455
+
456
+ val explanation =
457
+ hl """ The `_` placeholder syntax was used where it could not be bound.
458
+ |Consider explicitly writing the variable binding.
459
+ |
460
+ |This can be done by replacing `_` with a variable (eg. `x`)
461
+ |and adding ${" x =>" } where applicable.
462
+ |
463
+ |Example before:
464
+ |
465
+ | ${" { _ }" }
466
+ |
467
+ |Example after:
468
+ |
469
+ | ${" x => { x }" }
470
+ |
471
+ |Another common occurrence for this error is defining a val with `_`:
472
+ |
473
+ | ${" val a = _" }
474
+ |
475
+ |But this val definition isn't very useful, it can never be assigned
476
+ |another value. And thus will always remain uninitialized.
477
+ |Consider replacing the ${" val" } with ${" var" }:
478
+ |
479
+ | ${" var a = _" }
480
+ |
481
+ |Note that this use of `_` is not placeholder syntax,
482
+ |but an uninitialized var definition
483
+ """ .stripMargin
484
+ }
450
485
}
You can’t perform that action at this time.
0 commit comments