Merge pull request #1222 from triska/retain_string_of_nil

retain the string "[]" as is, instead of converting it to '[]' (i.e., "")
This commit is contained in:
Mark Thom
2022-01-16 11:58:15 -07:00
committed by GitHub

View File

@@ -735,9 +735,15 @@ impl MachineState {
pub fn value_to_str_like(&mut self, value: HeapCellValue) -> Option<AtomOrString> { pub fn value_to_str_like(&mut self, value: HeapCellValue) -> Option<AtomOrString> {
read_heap_cell!(value, read_heap_cell!(value,
(HeapCellValueTag::CStr, cstr_atom) => { (HeapCellValueTag::CStr, cstr_atom) => {
// avoid allocating a String if possible ... // avoid allocating a String if possible:
// We must be careful to preserve the string "[]" as is,
// instead of turning it into the atom [], i.e., "".
if cstr_atom == atom!("[]") {
Some(AtomOrString::String("[]".to_string()))
} else {
Some(AtomOrString::Atom(cstr_atom)) Some(AtomOrString::Atom(cstr_atom))
} }
}
(HeapCellValueTag::Atom, (atom, arity)) => { (HeapCellValueTag::Atom, (atom, arity)) => {
if arity == 0 { if arity == 0 {
// ... likewise. // ... likewise.