Dont desugar snil in errors

This commit is contained in:
imaqtkatt 2024-02-05 14:43:27 -03:00
parent 38b479d731
commit 9b7719d7f0
7 changed files with 17 additions and 14 deletions

View File

@ -219,17 +219,20 @@ impl<'a> Reader<'a> {
Term::App { fun: box Term::App { fun: ctr, arg: box Term::Num { val }, .. }, arg: tail, .. } => {
let tail = Self::resugar_string(tail, snil);
let char: String = unsafe { char::from_u32_unchecked(*val as u32) }.into();
if let Term::Str { val: tail } = tail {
Term::Str { val: char + &tail }
} else {
// FIXME: warnings are not good with this resugar
// Just make the constructor again
let fun = Term::App { tag: Tag::Static, fun: ctr.clone(), arg: Box::new(Term::Num { val: *val }) };
Term::App { tag: Tag::Static, fun: Box::new(fun), arg: Box::new(tail) }
match tail {
Term::Str { val: tail } => Term::Str { val: char + &tail },
Term::Ref { def_id } if def_id == *snil => Term::Str { val: char },
_ => {
// FIXME: warnings are not good with this resugar
// Just make the constructor again
let fun =
Term::App { tag: Tag::Static, fun: ctr.clone(), arg: Box::new(Term::Num { val: *val }) };
Term::App { tag: Tag::Static, fun: Box::new(fun), arg: Box::new(tail) }
}
}
}
// (SNil)
Term::Ref { def_id } if def_id == snil => Term::Str { val: String::new() },
// Term::Ref { def_id } if def_id == snil => Term::Str { val: String::new() },
other => std::mem::take(other),
}
}

View File

@ -2,4 +2,4 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/nested_str.hvm
---
(((SCons "a" ""), (SCons 97 (SCons "bc" ""))), ((SCons "ab" "c"), (SCons "ab" (SCons "cd" ""))))
(((SCons "a" SNil), (SCons 97 (SCons "bc" SNil))), ((SCons "ab" "c"), (SCons "ab" (SCons "cd" SNil))))

View File

@ -2,4 +2,4 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/unaplied_str.hvm
---
λa λb (SCons a (SCons 98 (SCons 99 (SCons b ""))))
λa λb (SCons a (SCons 98 (SCons 99 (SCons b SNil))))

View File

@ -2,4 +2,4 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/wrong_string.hvm
---
(SCons (*, 4) (SCons * ""))
(SCons (*, 4) (SCons * SNil))

View File

@ -2,4 +2,4 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_lazy/nested_str.hvm
---
(((SCons "a" ""), (SCons 97 (SCons "bc" ""))), ((SCons "ab" "c"), (SCons "ab" (SCons "cd" ""))))
(((SCons "a" SNil), (SCons 97 (SCons "bc" SNil))), ((SCons "ab" "c"), (SCons "ab" (SCons "cd" SNil))))

View File

@ -2,4 +2,4 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_lazy/unaplied_str.hvm
---
λa λb (SCons a (SCons 98 (SCons 99 (SCons b ""))))
λa λb (SCons a (SCons 98 (SCons 99 (SCons b SNil))))

View File

@ -2,4 +2,4 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_lazy/wrong_string.hvm
---
(SCons (*, 4) (SCons * ""))
(SCons (*, 4) (SCons * SNil))