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

Fix more fuzzing bugs #7535

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions crates/compiler/parse/src/expr.rs
Original file line number Diff line number Diff line change
@@ -3390,7 +3390,7 @@ fn starts_with_spaces_conservative(value: &Pattern<'_>) -> bool {
}

fn type_header_equivalent_to_pat<'a>(header: &TypeHeader<'a>, pat: &Pattern<'a>) -> bool {
match pat {
match pat.without_spaces() {
Pattern::Apply(func, args) => {
if !matches!(func.value, Pattern::Tag(tag) if header.name.value == tag) {
return false;
@@ -3399,7 +3399,7 @@ fn type_header_equivalent_to_pat<'a>(header: &TypeHeader<'a>, pat: &Pattern<'a>)
return false;
}
for (arg, var) in (*args).iter().zip(header.vars) {
match (arg.value, var.value) {
match (arg.value.without_spaces(), var.value.without_spaces()) {
(Pattern::Identifier { ident: left }, TypeVar::Identifier(right)) => {
if left != right {
return false;
@@ -3410,7 +3410,7 @@ fn type_header_equivalent_to_pat<'a>(header: &TypeHeader<'a>, pat: &Pattern<'a>)
}
true
}
Pattern::Tag(tag) => header.vars.is_empty() && header.name.value == *tag,
Pattern::Tag(tag) => header.vars.is_empty() && header.name.value == tag,
_ => false,
}
}
@@ -3991,9 +3991,10 @@ enum OperatorOrDef {
}

fn bin_op<'a>(check_for_defs: bool) -> impl Parser<'a, BinOp, EExpr<'a>> {
(move |_, state: State<'a>, min_indent| {
(move |arena: &'a Bump, state: State<'a>, min_indent| {
let start = state.pos();
let (_, op, state) = operator_help(EExpr::Start, EExpr::BadOperator, state, min_indent)?;
let (_, op, state) =
operator_help(arena, EExpr::Start, EExpr::BadOperator, state, min_indent)?;
let err_progress = if check_for_defs {
MadeProgress
} else {
@@ -4014,12 +4015,15 @@ fn bin_op<'a>(check_for_defs: bool) -> impl Parser<'a, BinOp, EExpr<'a>> {
}

fn operator<'a>() -> impl Parser<'a, OperatorOrDef, EExpr<'a>> {
(move |_, state, min_indent| operator_help(EExpr::Start, EExpr::BadOperator, state, min_indent))
.trace("operator")
(move |arena: &'a Bump, state, min_indent| {
operator_help(arena, EExpr::Start, EExpr::BadOperator, state, min_indent)
})
.trace("operator")
}

#[inline(always)]
fn operator_help<'a, F, G, E>(
arena: &'a Bump,
to_expectation: F,
to_error: G,
mut state: State<'a>,
@@ -4030,20 +4034,17 @@ where
G: Fn(&'a str, Position) -> E,
E: 'a,
{
match *state.bytes() {
[b'o', b'r', ..] => {
return Ok((
MadeProgress,
OperatorOrDef::BinOp(BinOp::Or),
state.advance(2),
))
let and_or = either(
parser::keyword(keyword::AND, EExpr::End),
parser::keyword(keyword::OR, EExpr::End),
);

match and_or.parse(arena, state.clone(), min_indent) {
Ok((MadeProgress, Either::First(_), state)) => {
return Ok((MadeProgress, OperatorOrDef::BinOp(BinOp::And), state))
}
[b'a', b'n', b'd', ..] => {
return Ok((
MadeProgress,
OperatorOrDef::BinOp(BinOp::And),
state.advance(3),
))
Ok((MadeProgress, Either::Second(_), state)) => {
return Ok((MadeProgress, OperatorOrDef::BinOp(BinOp::Or), state))
}
_ => {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
E : i
E = h
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@0-11 SpaceAfter(
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-9,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
],
spaces: [],
type_defs: [],
value_defs: [
AnnotatedBody {
ann_pattern: Apply(
@0-1 Tag(
"E",
),
[],
),
ann_type: @2-3 BoundVariable(
"i",
),
lines_between: [
Newline,
Newline,
],
body_pattern: @5-6 SpaceAfter(
Tag(
"E",
),
[
Newline,
],
),
body_expr: @8-9 Var {
module_name: "",
ident: "h",
},
},
],
},
@10-11 SpaceBefore(
Num(
"0",
),
[
Newline,
],
),
),
[
Newline,
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
E:i

E
=h
0
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a
ands
d
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
@0-11 SpaceAfter(
Defs(
Defs {
tags: [
EitherIndex(2147483648),
EitherIndex(2147483649),
],
regions: [
@0-1,
@2-9,
],
space_before: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 1 },
],
space_after: [
Slice<roc_parse::ast::CommentOrNewline> { start: 0, length: 0 },
Slice<roc_parse::ast::CommentOrNewline> { start: 1, length: 0 },
],
spaces: [
Newline,
],
type_defs: [],
value_defs: [
Stmt(
@0-1 Var {
module_name: "",
ident: "a",
},
),
Body(
@2-4 RecordDestructure(
[],
),
@5-9 Var {
module_name: "",
ident: "ands",
},
),
],
},
@10-11 SpaceBefore(
Var {
module_name: "",
ident: "d",
},
[
Newline,
],
),
),
[
Newline,
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a
{}=ands
d
2 changes: 2 additions & 0 deletions crates/compiler/test_syntax/tests/test_snapshots.rs
Original file line number Diff line number Diff line change
@@ -697,12 +697,14 @@ mod test_snapshots {
pass/return_record_update_comment_empty_fields.expr,
pass/return_then_nested_parens.expr,
pass/return_with_after.expr,
pass/sep_annotation.expr,
pass/separate_defs.moduledefs,
pass/single_arg_closure.expr,
pass/single_arg_with_underscore_closure.expr,
pass/single_question_binop_closure.expr,
pass/single_question_binop_tag.expr,
pass/single_underscore_closure.expr,
pass/sneaky_and_expr.expr,
pass/sneaky_implements_in_opaque_fn_type.expr,
pass/space_after_opt_field_pat.expr,
pass/space_before_colon.full,