Skip to content

Commit 6266d65

Browse files
committed
fix: ensured hints are relabelled under a label combinator
1 parent 5da4a42 commit 6266d65

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

parsley/shared/src/main/scala/parsley/internal/machine/instructions/ErrorInstrs.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ private [internal] final class RelabelHints(labels: Iterable[String]) extends In
3535
private [internal] final class RelabelErrorAndFail(labels: Iterable[String]) extends Instr {
3636
override def apply(ctx: Context): Unit = {
3737
ensureHandlerInstruction(ctx)
38-
//ctx.restoreHints() //FIXME: I'm not sure this was meant to be there in the first place
38+
// this has the effect of relabelling all hints since the start of the label combinator
39+
ctx.restoreHints()
3940
ctx.errs.error = ctx.useHints {
4041
// only use the label if the error message is generated at the same offset
4142
// as the check stack saved for the start of the `label` combinator.

parsley/shared/src/test/scala/parsley/ErrorTests.scala

+7
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ class ErrorTests extends ParsleyTest {
125125
}
126126

127127
it should "replace everything under the label" in {
128+
val p = (optional('a') *> 'b').label("hi")
129+
inside(p.parse("e")) {
130+
case Failure(TestError((1, 1), VanillaError(unex, exs, rs, 1))) =>
131+
unex should contain (Raw("e"))
132+
exs should contain.only(Named("hi"))
133+
rs shouldBe empty
134+
}
128135
val s = (optional('a') *> optional('b')).label("hi") *> 'c'
129136
inside(s.parse("e")) {
130137
case Failure(TestError((1, 1), VanillaError(unex, exs, rs, 1))) =>

0 commit comments

Comments
 (0)