Canonicalize the pattern in annotations

This commit is contained in:
Joshua Warner 2025-01-09 21:57:36 -08:00
parent 2331aa1d77
commit 408379f8d3
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
8 changed files with 86 additions and 3 deletions

View file

@ -311,7 +311,9 @@ fn desugar_value_def<'a>(
desugar_loc_pattern(env, scope, loc_pattern),
desugar_expr(env, scope, loc_expr),
),
ann @ Annotation(_, _) => *ann,
Annotation(ann_pattern, ann_type) => {
Annotation(*desugar_loc_pattern(env, scope, ann_pattern), *ann_type)
}
AnnotatedBody {
ann_pattern,
ann_type,
@ -319,7 +321,7 @@ fn desugar_value_def<'a>(
body_pattern,
body_expr,
} => AnnotatedBody {
ann_pattern,
ann_pattern: desugar_loc_pattern(env, scope, ann_pattern),
ann_type,
lines_between,
body_pattern: desugar_loc_pattern(env, scope, body_pattern),

View file

@ -11,7 +11,7 @@ fuzz_target!(|data: &[u8]| {
let ast = input.parse_in(&arena);
if let Ok(ast) = ast {
if !ast.is_malformed() {
input.check_invariants(|_| (), true, None);
input.check_invariants(|_| (), true, Some(false));
}
}
}

View file

@ -151,6 +151,24 @@ fn round_trip_once(input: Input<'_>, options: Options) -> Option<String> {
return Some("Formatting not stable".to_string());
}
let text = input.as_str();
let res = std::panic::catch_unwind(|| {
let new_arena = Bump::new();
actual.canonicalize(&new_arena, text);
});
if let Err(e) = res {
if options.minimize_full_error {
if let Some(s) = e.downcast_ref::<&'static str>() {
return Some(s.to_string());
}
if let Some(s) = e.downcast_ref::<String>() {
return Some(s.clone());
}
}
return Some("Panic during canonicalization".to_string());
}
None
}

View file

@ -0,0 +1,56 @@
@0-10 SpaceAfter(
Defs(
Defs {
tags: [
EitherIndex(2147483648),
],
regions: [
@0-8,
],
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: [
Annotation(
@0-6 RecordDestructure(
[
@1-5 OptionalField(
"p",
@4-5 SpaceBefore(
Var {
module_name: "",
ident: "m",
},
[
Newline,
],
),
),
],
),
@7-8 Apply(
"",
"J",
[],
),
),
],
},
@9-10 SpaceBefore(
Tag(
"O",
),
[
Newline,
],
),
),
[
Newline,
],
)

View file

@ -690,6 +690,7 @@ mod test_snapshots {
pass/single_arg_with_underscore_closure.expr,
pass/single_underscore_closure.expr,
pass/sneaky_implements_in_opaque_fn_type.expr,
pass/space_after_opt_field_pat.expr,
pass/space_before_colon.full,
pass/space_before_parens_space_after.expr,
pass/space_only_after_minus.expr,

View file

@ -43,6 +43,7 @@ pub fn set_panic_not_exit(inp: bool) {
#[inline(never)]
#[cold]
#[cfg(any(unix, windows, target_arch = "wasm32"))]
#[track_caller]
pub fn error_and_exit(args: fmt::Arguments) -> ! {
use core::panic;