fix: code gen tests now up to date using trace
fix: Formatter should take ErrorTerm and return "fail" fix: fail with no reason should just return ErrorTerm
This commit is contained in:
parent
624fdee9ea
commit
1d9878c5ee
|
@ -553,14 +553,15 @@ impl UntypedExpr {
|
|||
}
|
||||
|
||||
pub fn fail(reason: Option<Self>, location: Span) -> Self {
|
||||
if let Some(reason) = reason {
|
||||
UntypedExpr::Trace {
|
||||
location,
|
||||
kind: TraceKind::Error,
|
||||
then: Box::new(UntypedExpr::ErrorTerm { location }),
|
||||
text: Box::new(reason.unwrap_or_else(|| UntypedExpr::String {
|
||||
location,
|
||||
value: DEFAULT_ERROR_STR.to_string(),
|
||||
})),
|
||||
text: Box::new(reason),
|
||||
}
|
||||
} else {
|
||||
UntypedExpr::ErrorTerm { location }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -860,7 +860,7 @@ impl<'comments> Formatter<'comments> {
|
|||
.append(suffix)
|
||||
}
|
||||
|
||||
UntypedExpr::ErrorTerm { .. } => "error".to_doc(),
|
||||
UntypedExpr::ErrorTerm { .. } => "fail".to_doc(),
|
||||
|
||||
UntypedExpr::TraceIfFalse { value, .. } => self.trace_if_false(value),
|
||||
};
|
||||
|
|
|
@ -2,14 +2,6 @@
|
|||
source: crates/aiken-lang/src/parser/expr/fail_todo_trace.rs
|
||||
description: "Code:\n\nfail\n"
|
||||
---
|
||||
Trace {
|
||||
kind: Error,
|
||||
ErrorTerm {
|
||||
location: 0..4,
|
||||
then: ErrorTerm {
|
||||
location: 0..4,
|
||||
},
|
||||
text: String {
|
||||
location: 0..4,
|
||||
value: "aiken::error",
|
||||
},
|
||||
}
|
||||
|
|
|
@ -24,17 +24,9 @@ When {
|
|||
},
|
||||
],
|
||||
guard: None,
|
||||
then: Trace {
|
||||
kind: Error,
|
||||
location: 28..32,
|
||||
then: ErrorTerm {
|
||||
location: 28..32,
|
||||
},
|
||||
text: String {
|
||||
location: 28..32,
|
||||
value: "aiken::error",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ fn assert_uplc(source_code: &str, expected: Term<Name>, should_fail: bool) {
|
|||
let mut project = TestProject::new();
|
||||
|
||||
let modules = CheckedModules::singleton(project.check(project.parse(source_code)));
|
||||
|
||||
let mut generator = modules.new_generator(
|
||||
&project.functions,
|
||||
&project.data_types,
|
||||
|
@ -2865,6 +2866,10 @@ fn when_tuple_deconstruction() {
|
|||
),
|
||||
)
|
||||
.apply(Term::var("x"))
|
||||
.delayed_if_else(
|
||||
Term::bool(true),
|
||||
Term::bool(false).trace(Term::string("a.idx == x ? False")),
|
||||
)
|
||||
.lambda("x")
|
||||
.apply(
|
||||
Term::un_i_data()
|
||||
|
@ -4233,3 +4238,102 @@ fn expect_head_cast_data_with_tail() {
|
|||
false,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn init_3() {
|
||||
let src = r#"
|
||||
|
||||
pub fn init(self: List<a>) -> Option<List<a>> {
|
||||
when self is {
|
||||
[] -> None
|
||||
_ -> Some(do_init(self))
|
||||
}
|
||||
}
|
||||
|
||||
fn do_init(self: List<a>) -> List<a> {
|
||||
when self is {
|
||||
[] -> fail @"unreachable"
|
||||
[_] ->
|
||||
[]
|
||||
[x, ..xs] ->
|
||||
[x, ..do_init(xs)]
|
||||
}
|
||||
}
|
||||
|
||||
test init_3() {
|
||||
init([1, 2, 3, 4]) == Some([1, 2, 3])
|
||||
}
|
||||
"#;
|
||||
|
||||
assert_uplc(
|
||||
src,
|
||||
Term::equals_data()
|
||||
.apply(
|
||||
Term::var("init")
|
||||
.lambda("init")
|
||||
.apply(
|
||||
Term::var("self")
|
||||
.delayed_choose_list(
|
||||
Term::data(Data::constr(1, vec![])),
|
||||
Term::constr_data().apply(Term::integer(0.into())).apply(
|
||||
Term::mk_cons()
|
||||
.apply(
|
||||
Term::list_data().apply(
|
||||
Term::var("do_init").apply(Term::var("self")),
|
||||
),
|
||||
)
|
||||
.apply(Term::empty_list()),
|
||||
),
|
||||
)
|
||||
.lambda("self"),
|
||||
)
|
||||
.lambda("do_init")
|
||||
.apply(Term::var("do_init").apply(Term::var("do_init")))
|
||||
.lambda("do_init")
|
||||
.apply(
|
||||
Term::var("self")
|
||||
.delayed_choose_list(
|
||||
Term::Error.trace(Term::string("unreachable")),
|
||||
Term::var("tail_1")
|
||||
.delayed_choose_list(
|
||||
Term::empty_list(),
|
||||
Term::mk_cons()
|
||||
.apply(Term::i_data().apply(Term::var("x")))
|
||||
.apply(
|
||||
Term::var("do_init")
|
||||
.apply(Term::var("do_init"))
|
||||
.apply(Term::var("xs")),
|
||||
)
|
||||
.lambda("xs")
|
||||
.apply(Term::tail_list().apply(Term::var("self")))
|
||||
.lambda("x")
|
||||
.apply(
|
||||
Term::un_i_data().apply(
|
||||
Term::head_list().apply(Term::var("self")),
|
||||
),
|
||||
),
|
||||
)
|
||||
.lambda("tail_1")
|
||||
.apply(Term::tail_list().apply(Term::var("self"))),
|
||||
)
|
||||
.lambda("self")
|
||||
.lambda("do_init"),
|
||||
)
|
||||
.apply(Term::list_values(vec![
|
||||
Constant::Data(Data::integer(1.into())),
|
||||
Constant::Data(Data::integer(2.into())),
|
||||
Constant::Data(Data::integer(3.into())),
|
||||
Constant::Data(Data::integer(4.into())),
|
||||
])),
|
||||
)
|
||||
.apply(Term::data(Data::constr(
|
||||
0,
|
||||
vec![Data::list(vec![
|
||||
Data::integer(1.into()),
|
||||
Data::integer(2.into()),
|
||||
Data::integer(3.into()),
|
||||
])],
|
||||
))),
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue