Skip to content

Commit dec5492

Browse files
authored
Fixed prioritisation of nested errors (#932)
1 parent 726bfaa commit dec5492

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/combinator.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,8 @@ where
13111311
{
13121312
#[inline(always)]
13131313
fn go<M: Mode>(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult<M, O> {
1314+
let before = inp.save();
1315+
13141316
let inp2 = self.parser_b.go::<Emit>(inp)?;
13151317

13161318
let alt = inp.errors.alt.take();
@@ -1327,11 +1329,21 @@ where
13271329
&mut memos,
13281330
);
13291331

1330-
// TODO: Translate secondary error offsets too
1332+
// Translate error offsets to the start of the outer pattern
1333+
// This is not idea, but it mostly prevents error prioritisation issues
13311334
let new_alt = inp.errors.alt.take();
13321335
inp.errors.alt = alt;
13331336
if let Some(new_alt) = new_alt {
1334-
inp.add_alt_err(&inp.cursor().inner, new_alt.err);
1337+
inp.add_alt_err(&before.cursor().inner, new_alt.err);
1338+
}
1339+
for err in inp
1340+
.errors
1341+
.secondary
1342+
.get_mut(before.err_count..)
1343+
.into_iter()
1344+
.flatten()
1345+
{
1346+
err.pos = before.cursor().inner.clone();
13351347
}
13361348

13371349
res

0 commit comments

Comments
 (0)