Skip to content

Commit

Permalink
fix: ensured hints are relabelled under a label combinator
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Jan 12, 2024
1 parent 5da4a42 commit 6266d65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ private [internal] final class RelabelHints(labels: Iterable[String]) extends In
private [internal] final class RelabelErrorAndFail(labels: Iterable[String]) extends Instr {
override def apply(ctx: Context): Unit = {
ensureHandlerInstruction(ctx)
//ctx.restoreHints() //FIXME: I'm not sure this was meant to be there in the first place
// this has the effect of relabelling all hints since the start of the label combinator
ctx.restoreHints()
ctx.errs.error = ctx.useHints {
// only use the label if the error message is generated at the same offset
// as the check stack saved for the start of the `label` combinator.
Expand Down
7 changes: 7 additions & 0 deletions parsley/shared/src/test/scala/parsley/ErrorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ class ErrorTests extends ParsleyTest {
}

it should "replace everything under the label" in {
val p = (optional('a') *> 'b').label("hi")
inside(p.parse("e")) {
case Failure(TestError((1, 1), VanillaError(unex, exs, rs, 1))) =>
unex should contain (Raw("e"))
exs should contain.only(Named("hi"))
rs shouldBe empty
}
val s = (optional('a') *> optional('b')).label("hi") *> 'c'
inside(s.parse("e")) {
case Failure(TestError((1, 1), VanillaError(unex, exs, rs, 1))) =>
Expand Down

0 comments on commit 6266d65

Please sign in to comment.