Return readback error for nested strings

This commit is contained in:
imaqtkatt 2024-01-23 09:09:25 -03:00 committed by LunaAmora
parent 46abc67967
commit 379414aa36
3 changed files with 15 additions and 2 deletions

View File

@ -272,15 +272,21 @@ impl<'a> Reader<'a> {
let mut s = String::new();
fn go(t: &mut Term, s: &mut String, rd: &mut Reader<'_>) {
match t {
Term::Num { val } => s.push(unsafe { char::from_u32_unchecked(*val as u32) }),
Term::Lam { bod, .. } => go(bod, s, rd),
Term::App { tag, arg, .. } if *tag == Tag::string_scons_head() => go(arg, s, rd),
Term::App { tag, arg, .. } if *tag == Tag::string_scons_head() => {
if let Term::Num { val } = &**arg {
s.push(unsafe { char::from_u32_unchecked(*val as u32) });
} else {
rd.error(ReadbackError::InvalidStrTerm)
}
}
Term::App { fun, arg, .. } => {
go(fun, s, rd);
go(arg, s, rd);
}
Term::Var { .. } => {}
Term::Chn { .. }
| Term::Num { .. } // expected to appear only inside SCons.head
| Term::Lnk { .. }
| Term::Let { .. }
| Term::Tup { .. }

View File

@ -0,0 +1 @@
Main = (SCons "a" SNil)

View File

@ -0,0 +1,6 @@
---
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/nested_str.hvm
---
Invalid readback: [InvalidStrTerm]
""