From 6266d65f38451d992491bb10e05c6bbaf5e36ac3 Mon Sep 17 00:00:00 2001 From: Jamie Willis Date: Fri, 12 Jan 2024 16:42:43 +0000 Subject: [PATCH] fix: ensured hints are relabelled under a label combinator --- .../internal/machine/instructions/ErrorInstrs.scala | 3 ++- parsley/shared/src/test/scala/parsley/ErrorTests.scala | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/parsley/shared/src/main/scala/parsley/internal/machine/instructions/ErrorInstrs.scala b/parsley/shared/src/main/scala/parsley/internal/machine/instructions/ErrorInstrs.scala index 93e374f1f..040035abc 100644 --- a/parsley/shared/src/main/scala/parsley/internal/machine/instructions/ErrorInstrs.scala +++ b/parsley/shared/src/main/scala/parsley/internal/machine/instructions/ErrorInstrs.scala @@ -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. diff --git a/parsley/shared/src/test/scala/parsley/ErrorTests.scala b/parsley/shared/src/test/scala/parsley/ErrorTests.scala index 717c9c3ec..6c249ecd1 100644 --- a/parsley/shared/src/test/scala/parsley/ErrorTests.scala +++ b/parsley/shared/src/test/scala/parsley/ErrorTests.scala @@ -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))) =>