fix unwrapping of trailing expr

This commit is contained in:
Luke Boswell 2024-04-17 09:54:29 +10:00
parent 7a84dcd39c
commit 0198a683c7
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
4 changed files with 89 additions and 112 deletions

View file

@ -9,6 +9,7 @@ use bumpalo::Bump;
use roc_collections::soa::{EitherIndex, Index, Slice};
use roc_error_macros::internal_error;
use roc_module::called_via::{BinOp, CalledVia, UnaryOp};
use roc_module::ident::ModuleName;
use roc_region::all::{Loc, Position, Region};
#[derive(Debug, Clone, PartialEq, Eq)]
@ -450,6 +451,24 @@ pub fn is_loc_expr_suffixed(loc_expr: &Loc<Expr>) -> bool {
}
}
pub fn wrap_in_task_ok<'a>(arena: &'a Bump, loc_expr: &'a Loc<Expr<'a>>) -> &'a Loc<Expr<'a>> {
arena.alloc(Loc::at(
loc_expr.region,
Expr::Apply(
arena.alloc(Loc::at(
loc_expr.region,
Expr::Var {
module_name: ModuleName::TASK,
ident: "ok",
suffixed: 0,
},
)),
arena.alloc([loc_expr]),
CalledVia::BangSuffix,
),
))
}
pub fn split_around<T>(items: &[T], target: usize) -> (&[T], &[T]) {
let (before, rest) = items.split_at(target);
let after = &rest[1..];