From b1c76fe0c31484d76ebcf7a2f6694b60d4c0c9fc Mon Sep 17 00:00:00 2001 From: Jamie Willis Date: Tue, 7 Nov 2023 12:41:17 +0000 Subject: [PATCH] fix: moved where hint restore happens from label to amend --- .../main/scala/parsley/internal/deepembedding/Cont.scala | 1 + .../parsley/internal/machine/instructions/ErrorInstrs.scala | 6 ++++-- parsley/shared/src/test/scala/parsley/ErrorTests.scala | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/parsley/shared/src/main/scala/parsley/internal/deepembedding/Cont.scala b/parsley/shared/src/main/scala/parsley/internal/deepembedding/Cont.scala index 4bba457c4..269a3623f 100644 --- a/parsley/shared/src/main/scala/parsley/internal/deepembedding/Cont.scala +++ b/parsley/shared/src/main/scala/parsley/internal/deepembedding/Cont.scala @@ -6,6 +6,7 @@ package parsley.internal.deepembedding import scala.annotation.tailrec + import org.typelevel.scalaccompat.annotation.uncheckedVariance212 // Trampoline for CPS 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 66ce96b12..93e374f1f 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,7 @@ 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() + //ctx.restoreHints() //FIXME: I'm not sure this was meant to be there in the first place 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. @@ -45,7 +45,7 @@ private [internal] final class RelabelErrorAndFail(labels: Iterable[String]) ext ctx.fail() } // $COVERAGE-OFF$ - override def toString: String = s"ApplyError($labels)" + override def toString: String = s"RelabelErrorAndFail($labels)" // $COVERAGE-ON$ } @@ -62,6 +62,7 @@ private [internal] object HideHints extends Instr { // $COVERAGE-ON$ } +// FIXME: Gigaparsec points out the hints aren't being used here, I believe they should be! private [internal] object HideErrorAndFail extends Instr { override def apply(ctx: Context): Unit = { ensureHandlerInstruction(ctx) @@ -119,6 +120,7 @@ private [internal] class ApplyReasonAndFail(reason: String) extends Instr { private [internal] class AmendAndFail private (partial: Boolean) extends Instr { override def apply(ctx: Context): Unit = { ensureHandlerInstruction(ctx) + ctx.restoreHints() //TODO: verify this is ok; it feels more right than the restore on the labelling ctx.handlers = ctx.handlers.tail ctx.errs.error = ctx.errs.error.amend(partial, ctx.states.offset, ctx.states.line, ctx.states.col) ctx.states = ctx.states.tail diff --git a/parsley/shared/src/test/scala/parsley/ErrorTests.scala b/parsley/shared/src/test/scala/parsley/ErrorTests.scala index d4e8fae35..2f20a5890 100644 --- a/parsley/shared/src/test/scala/parsley/ErrorTests.scala +++ b/parsley/shared/src/test/scala/parsley/ErrorTests.scala @@ -209,7 +209,7 @@ class ErrorTests extends ParsleyTest { } } - it should "not replace hints if input is consumed" in { + it should "suppress hints even if input is consumed" in { inside((many(digit).hide <* eof).parse("1e")) { case Failure(TestError((1, 2), VanillaError(unex, exs, rs, 1))) => unex should contain (Raw("e"))