File tree 2 files changed +37
-1
lines changed
2 files changed +37
-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 @@ -400,4 +400,40 @@ object messages {
400
400
| (( ${nestedRepresentation})) """ .stripMargin
401
401
}
402
402
}
403
+
404
+ case class UnboundPlaceholderParameter ()(implicit ctx: Context )
405
+ extends Message (16 ) {
406
+ val kind = " Syntax"
407
+
408
+ val msg = hl " unbound placeholder parameter; incorrect use of `_` "
409
+
410
+ val explanation =
411
+ hl """ The `_` placeholder syntax was used where it could not be bound.
412
+ |Consider explicitly writing the variable binding.
413
+ |
414
+ |This can be done by replacing `_` with a variable (eg. `x`)
415
+ |and adding ${" x =>" } where applicable.
416
+ |
417
+ |Example before:
418
+ |
419
+ | ${" { _ }" }
420
+ |
421
+ |Example after:
422
+ |
423
+ | ${" x => { x }" }
424
+ |
425
+ |Another common occurrence for this error is defining a val with `_`:
426
+ |
427
+ | ${" val a = _" }
428
+ |
429
+ |But this val definition isn't very useful, it can never be assigned
430
+ |another value. And thus will always remain uninitialized.
431
+ |Consider replacing the ${" val" } with ${" var" }:
432
+ |
433
+ | ${" var a = _" }
434
+ |
435
+ |Note that this use of `_` is not placeholder syntax,
436
+ |but an uninitialized var definition
437
+ """ .stripMargin
438
+ }
403
439
}
You can’t perform that action at this time.
0 commit comments