Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Commit d93e12a

Browse files
committed
Fixed TryMap error location
1 parent 6837537 commit d93e12a

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/combinator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ where
546546
match (self.mapper)(out, span) {
547547
Ok(out) => Ok(M::bind(|| out)),
548548
Err(err) => {
549-
inp.add_alt_err(inp.offset().offset, err);
549+
inp.add_alt_err(before.offset, err);
550550
Err(())
551551
}
552552
}

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,5 +3543,20 @@ mod tests {
35433543
);
35443544
<Rich<_, _, _> as LabelError<&str, _>>::in_context(&mut err, "greeting", (0..3).into());
35453545
assert_eq!(parser().parse("help").into_errors(), vec![err]);
3546+
3547+
fn parser2<'src>() -> impl Parser<'src, &'src str, (), extra::Err<Rich<'src, char>>> {
3548+
text::keyword("hello")
3549+
.labelled("greeting")
3550+
.as_context()
3551+
.ignored()
3552+
}
3553+
3554+
let mut err = <Rich<_> as crate::Error<&str>>::expected_found(
3555+
Some(Some('h'.into())),
3556+
None,
3557+
(0..7).into(),
3558+
);
3559+
<Rich<_, _, _> as LabelError<&str, _>>::label_with(&mut err, "greeting");
3560+
assert_eq!(parser2().parse("goodbye").into_errors(), vec![err]);
35463561
}
35473562
}

0 commit comments

Comments
 (0)