File tree 2 files changed +49
-2
lines changed
2 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -623,7 +623,7 @@ object Parsers {
623
623
if (inPattern) Block (Nil , inBraces(pattern()))
624
624
else expr()
625
625
else {
626
- syntaxErrorOrIncomplete( " error in interpolated string: identifier or block expected " )
626
+ ctx. error( InterpolatedStringError () )
627
627
EmptyTree
628
628
}
629
629
})
@@ -1489,7 +1489,7 @@ object Parsers {
1489
1489
1490
1490
private def addModifier (mods : Modifiers ): Modifiers = {
1491
1491
val flag = flagOfToken(in.token)
1492
- if (mods is flag) syntaxError(" repeated modifier " )
1492
+ if (mods is flag) syntaxError(RepeatedModifier (flag.toString) )
1493
1493
val res = addFlag(mods, flag)
1494
1494
in.nextToken()
1495
1495
res
Original file line number Diff line number Diff line change @@ -400,4 +400,51 @@ object messages {
400
400
| (( ${nestedRepresentation})) """ .stripMargin
401
401
}
402
402
}
403
+
404
+ case class RepeatedModifier (modifier : String )(implicit ctx: Context ) extends Message (14 ) {
405
+ val kind = " Syntax"
406
+
407
+ val msg = hl """ repeated modifier $modifier"""
408
+
409
+ val code1 = hl """ private private val Origin = Point(0, 0) """
410
+
411
+ val code2 = hl """ private final val Origin = Point(0, 0) """
412
+
413
+ val explanation =
414
+ hl """ This happens when you accidentally specify the same modifier twice.
415
+ |
416
+ |Example:
417
+ |
418
+ | $code1
419
+ |
420
+ |instead of
421
+ |
422
+ | $code2
423
+ |
424
+ | """ .stripMargin
425
+ }
426
+
427
+ case class InterpolatedStringError ()(implicit ctx: Context ) extends Message (15 ) {
428
+ val kind = " Syntax"
429
+
430
+ val msg = " error in interpolated string: identifier or block expected"
431
+
432
+ val code1 = " s\" $new Point(0, 0)\" "
433
+
434
+ val code2 = " s\" ${new Point(0, 0)}\" "
435
+
436
+ val explanation =
437
+ hl """
438
+ |This usually happens when you forget to place your expressions inside curly braces.
439
+ |
440
+ | $code1
441
+ |
442
+ |should be written as
443
+ |
444
+ | $code2
445
+ |
446
+ | """ .stripMargin
447
+
448
+ }
449
+
403
450
}
You can’t perform that action at this time.
0 commit comments