Format code

This commit is contained in:
Sam Mohr 2024-08-14 22:26:32 -07:00
parent 4870f56a18
commit 0fd0cc11aa
No known key found for this signature in database
GPG key ID: EA41D161A3C1BC99
5 changed files with 56 additions and 20 deletions

View file

@ -648,9 +648,7 @@ pub fn canonicalize_expr<'a>(
(answer, Output::default())
}
ast::Expr::Record(fields) => {
canonicalize_record(env, var_store, scope, region, *fields)
}
ast::Expr::Record(fields) => canonicalize_record(env, var_store, scope, region, *fields),
ast::Expr::RecordUpdate {
fields,
update: loc_update,
@ -1119,7 +1117,9 @@ pub fn canonicalize_expr<'a>(
output,
)
}
ast::Expr::TrySuffix { .. } => internal_error!("a Expr::TrySuffix expression was not completely removed in desugar_value_def_suffixed"),
ast::Expr::TrySuffix { .. } => internal_error!(
"a Expr::TrySuffix expression was not completely removed in desugar_value_def_suffixed"
),
ast::Expr::Tag(tag) => {
let variant_var = var_store.fresh();
let ext_var = var_store.fresh();
@ -1371,7 +1371,10 @@ pub fn canonicalize_expr<'a>(
use roc_problem::can::RuntimeError::*;
let sub_region = Region::span_across(&loc_name.region, &loc_value.region);
let problem = OptionalFieldInRecordBuilder {record: region, field: sub_region };
let problem = OptionalFieldInRecordBuilder {
record: region,
field: sub_region,
};
env.problem(Problem::RuntimeError(problem.clone()));
(RuntimeError(problem), Output::default())

View file

@ -71,7 +71,10 @@ fn init_unwrapped_err<'a>(
Some(..) => {
// we have a def pattern, so no need to generate a new pattern
// as this should only be created in the first call from a def
Err(EUnwrapped::UnwrappedDefExpr { loc_expr: unwrapped_expr, target })
Err(EUnwrapped::UnwrappedDefExpr {
loc_expr: unwrapped_expr,
target,
})
}
None => {
// Provide an intermediate answer expression and pattern when unwrapping a
@ -165,10 +168,16 @@ pub fn unwrap_suffixed_expression<'a>(
.alloc(Loc::at(loc_expr.region, Expect(condition, unwrapped_expr)));
return Ok(new_expect);
}
Err(EUnwrapped::UnwrappedDefExpr { loc_expr: unwrapped_expr, target, }) => {
Err(EUnwrapped::UnwrappedDefExpr {
loc_expr: unwrapped_expr,
target,
}) => {
let new_expect = arena
.alloc(Loc::at(loc_expr.region, Expect(condition, unwrapped_expr)));
Err(EUnwrapped::UnwrappedDefExpr { loc_expr: new_expect, target })
Err(EUnwrapped::UnwrappedDefExpr {
loc_expr: new_expect,
target,
})
}
Err(EUnwrapped::UnwrappedSubExpr {
sub_arg: unwrapped_expr,
@ -330,9 +339,8 @@ pub fn unwrap_suffixed_expression_apply_help<'a>(
Err(EUnwrapped::UnwrappedDefExpr { loc_expr: new_apply, target })
}
Err(EUnwrapped::UnwrappedSubExpr { sub_arg: unwrapped_function, sub_pat, sub_new, target }) => {
let new_apply = arena.alloc(Loc::at(loc_expr.region, Expr::Apply(sub_new, local_args, called_via)));
Err(EUnwrapped::UnwrappedSubExpr { sub_arg: unwrapped_function, sub_pat, sub_new:new_apply, target })
}
Err(err) => Err(err)
@ -536,8 +544,15 @@ pub fn unwrap_suffixed_expression_if_then_else_help<'a>(
sub_new,
target,
}) => {
let unwrapped_final_else =
apply_try_function(arena, sub_arg.region, sub_arg, sub_pat, sub_new, None, target);
let unwrapped_final_else = apply_try_function(
arena,
sub_arg.region,
sub_arg,
sub_pat,
sub_new,
None,
target,
);
let new_if = arena.alloc(Loc::at(
loc_expr.region,
@ -673,7 +688,7 @@ pub fn unwrap_suffixed_expression_defs_help<'a>(
return unwrap_suffixed_expression(
arena,
apply_try_function(
arena,
arena,
def_expr.region,
unwrapped_expr,
def_pattern,
@ -840,12 +855,18 @@ fn unwrap_low_level_dbg<'a>(
));
Ok(&*new_dbg)
}
Err(EUnwrapped::UnwrappedDefExpr { loc_expr: unwrapped_expr, target }) => {
Err(EUnwrapped::UnwrappedDefExpr {
loc_expr: unwrapped_expr,
target,
}) => {
let new_dbg = arena.alloc(Loc::at(
loc_expr.region,
LowLevelDbg(dbg_src, arg, unwrapped_expr),
));
Err(EUnwrapped::UnwrappedDefExpr { loc_expr: new_dbg, target })
Err(EUnwrapped::UnwrappedDefExpr {
loc_expr: new_dbg,
target,
})
}
Err(EUnwrapped::UnwrappedSubExpr {
sub_arg: unwrapped_expr,

View file

@ -9,7 +9,8 @@ use crate::spaces::{
use crate::Buf;
use roc_module::called_via::{self, BinOp};
use roc_parse::ast::{
is_expr_suffixed, AssignedField, Base, Collection, CommentOrNewline, Expr, ExtractSpaces, OldRecordBuilderField, Pattern, TryTarget, WhenBranch
is_expr_suffixed, AssignedField, Base, Collection, CommentOrNewline, Expr, ExtractSpaces,
OldRecordBuilderField, Pattern, TryTarget, WhenBranch,
};
use roc_parse::ast::{StrLiteral, StrSegment};
use roc_parse::ident::Accessor;

View file

@ -1,5 +1,9 @@
use crate::ast::{
is_expr_suffixed, AssignedField, Collection, CommentOrNewline, Defs, Expr, ExtractSpaces, Implements, ImplementsAbilities, ImportAlias, ImportAsKeyword, ImportExposingKeyword, ImportedModuleName, IngestedFileAnnotation, IngestedFileImport, ModuleImport, ModuleImportParams, OldRecordBuilderField, Pattern, Spaceable, Spaced, Spaces, SpacesBefore, TryTarget, TypeAnnotation, TypeDef, TypeHeader, ValueDef
is_expr_suffixed, AssignedField, Collection, CommentOrNewline, Defs, Expr, ExtractSpaces,
Implements, ImplementsAbilities, ImportAlias, ImportAsKeyword, ImportExposingKeyword,
ImportedModuleName, IngestedFileAnnotation, IngestedFileImport, ModuleImport,
ModuleImportParams, OldRecordBuilderField, Pattern, Spaceable, Spaced, Spaces, SpacesBefore,
TryTarget, TypeAnnotation, TypeDef, TypeHeader, ValueDef,
};
use crate::blankspace::{
loc_space0_e, require_newline_or_eof, space0_after_e, space0_around_ee, space0_before_e,
@ -165,8 +169,12 @@ fn record_field_access_chain<'a>() -> impl Parser<'a, Vec<'a, Suffix<'a>>, EExpr
)
)
),
map(byte(b'!', EExpr::Access), |_| Suffix::TrySuffix(TryTarget::Task)),
map(byte(b'?', EExpr::Access), |_| Suffix::TrySuffix(TryTarget::Result)),
map(byte(b'!', EExpr::Access), |_| Suffix::TrySuffix(
TryTarget::Task
)),
map(byte(b'?', EExpr::Access), |_| Suffix::TrySuffix(
TryTarget::Result
)),
))
}

View file

@ -722,7 +722,10 @@ impl<'a> Normalize<'a> for Expr<'a> {
Expr::RecordAccess(a, b) => Expr::RecordAccess(arena.alloc(a.normalize(arena)), b),
Expr::AccessorFunction(a) => Expr::AccessorFunction(a),
Expr::TupleAccess(a, b) => Expr::TupleAccess(arena.alloc(a.normalize(arena)), b),
Expr::TrySuffix { expr: a, target } => Expr::TrySuffix { expr: arena.alloc(a.normalize(arena)), target },
Expr::TrySuffix { expr: a, target } => Expr::TrySuffix {
expr: arena.alloc(a.normalize(arena)),
target,
},
Expr::List(a) => Expr::List(a.normalize(arena)),
Expr::RecordUpdate { update, fields } => Expr::RecordUpdate {
update: arena.alloc(update.normalize(arena)),