Skip to content

Commit

Permalink
fix: moved where hint restore happens from label to amend
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Nov 7, 2023
1 parent 3a521c4 commit b1c76fe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package parsley.internal.deepembedding

import scala.annotation.tailrec

import org.typelevel.scalaccompat.annotation.uncheckedVariance212

// Trampoline for CPS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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$
}

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion parsley/shared/src/test/scala/parsley/ErrorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit b1c76fe

Please sign in to comment.