Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal error when translating Ast to Hir #1047

Closed
conradludgate opened this issue Jul 17, 2023 · 0 comments
Closed

internal error when translating Ast to Hir #1047

conradludgate opened this issue Jul 17, 2023 · 0 comments

Comments

@conradludgate
Copy link

What version of regex are you using?

regex-syntax 0.7.4

Describe the bug at a high level.

There are Asts that can be created that cause internal errors to be panicked when being translated into Hir.

These Ast's are nonsense, but can be generated using the Arbitrary integration.

What are the steps to reproduce the behavior?

use regex_syntax::{ast::{Span, Position, Ast, Alternation, Concat}, hir::translate::Translator};

let span = Span::splat(Position::new(0, 0, 0));
let ast = Ast::Alternation(Alternation {
    span,
    asts: vec![Ast::Concat(Concat { span, asts: vec![] })],
});

let mut t = Translator::new();
let hir_result = t.translate("", &ast);

What is the actual behavior?

panicked at 'internal error: entered unreachable code: expected expr or concat, got alt branch marker', /Users/conrad/.cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-syntax-0.7.4/src/hir/translate.rs:769:17

What is the expected behavior?

Return an error case from translate

BurntSushi added a commit that referenced this issue Oct 8, 2023
These panics I do not believe can occur from an actual pattern, since
the parser will either never produce such things or will return an
error. But still, the Ast->Hir translator shouldn't panic in such cases.

Actually, the non-sensical Ast values are actually somewhat sensible,
and they don't map to invalid regexes. These panics were likely the
result of the regex crate not supporting empty patterns or "fail"
patterns particularly well in the fast. But now that we do, we can just
let the Asts through and generate the Hir you'd expect.

Fixes #1047
BurntSushi added a commit that referenced this issue Oct 9, 2023
These panics I do not believe can occur from an actual pattern, since
the parser will either never produce such things or will return an
error. But still, the Ast->Hir translator shouldn't panic in such cases.

Actually, the non-sensical Ast values are actually somewhat sensible,
and they don't map to invalid regexes. These panics were likely the
result of the regex crate not supporting empty patterns or "fail"
patterns particularly well in the fast. But now that we do, we can just
let the Asts through and generate the Hir you'd expect.

Fixes #1047
BurntSushi added a commit that referenced this issue Oct 9, 2023
These panics I do not believe can occur from an actual pattern, since
the parser will either never produce such things or will return an
error. But still, the Ast->Hir translator shouldn't panic in such cases.

Actually, the non-sensical Ast values are actually somewhat sensible,
and they don't map to invalid regexes. These panics were likely the
result of the regex crate not supporting empty patterns or "fail"
patterns particularly well in the fast. But now that we do, we can just
let the Asts through and generate the Hir you'd expect.

Fixes #1047
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants