Skip to content

Commit

Permalink
Merge pull request #1222 from triska/retain_string_of_nil
Browse files Browse the repository at this point in the history
retain the string "[]" as is, instead of converting it to '[]' (i.e., "")
  • Loading branch information
mthom authored Jan 16, 2022
2 parents 83378e4 + 11d504e commit 7baa187
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/machine/system_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,14 @@ impl MachineState {
pub fn value_to_str_like(&mut self, value: HeapCellValue) -> Option<AtomOrString> {
read_heap_cell!(value,
(HeapCellValueTag::CStr, cstr_atom) => {
// avoid allocating a String if possible ...
Some(AtomOrString::Atom(cstr_atom))
// 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))
}
}
(HeapCellValueTag::Atom, (atom, arity)) => {
if arity == 0 {
Expand Down

0 comments on commit 7baa187

Please sign in to comment.