Skip to content

Commit a6d3723

Browse files
authored
Merge pull request #1615 from sebastianharko/master
Add error messages - Parsers.scala:626 and Parsers.scala:1492
2 parents b008ceb + ac24603 commit a6d3723

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ object Parsers {
623623
if (inPattern) Block(Nil, inBraces(pattern()))
624624
else expr()
625625
else {
626-
syntaxErrorOrIncomplete("error in interpolated string: identifier or block expected")
626+
ctx.error(InterpolatedStringError())
627627
EmptyTree
628628
}
629629
})
@@ -1489,7 +1489,7 @@ object Parsers {
14891489

14901490
private def addModifier(mods: Modifiers): Modifiers = {
14911491
val flag = flagOfToken(in.token)
1492-
if (mods is flag) syntaxError("repeated modifier")
1492+
if (mods is flag) syntaxError(RepeatedModifier(flag.toString))
14931493
val res = addFlag(mods, flag)
14941494
in.nextToken()
14951495
res

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

+47
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,51 @@ object messages {
400400
| ((${nestedRepresentation}))""".stripMargin
401401
}
402402
}
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+
403450
}

0 commit comments

Comments
 (0)