From 4cde8cd5015057e01901be241ddf802100327df1 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Fri, 3 Dec 2021 21:18:13 -0700 Subject: [PATCH] fix bug in error_form --- src/machine/machine_errors.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/machine/machine_errors.rs b/src/machine/machine_errors.rs index d62e5b5b..cae977e5 100644 --- a/src/machine/machine_errors.rs +++ b/src/machine/machine_errors.rs @@ -503,22 +503,29 @@ impl MachineState { } pub(super) fn error_form(&mut self, err: MachineError, src: FunctorStub) -> MachineStub { - let location = err.location; - let err_len = err.len(); - let h = self.heap.len(); + let location = err.location; + let stub_addition_len = if err.len() == 1 { + 0 // if err contains 1 cell, it can be inlined at stub[1]. + } else { + err.len() + }; let mut stub = vec![ atom_as_cell!(atom!("error"), 2), str_loc_as_cell!(h + 3), - str_loc_as_cell!(h + 3 + err_len), + str_loc_as_cell!(h + 3 + stub_addition_len), ]; - stub.extend(err.into_iter(3)); + if stub_addition_len > 0 { + stub.extend(err.into_iter(3)); + } else { + stub[1] = err.stub[0]; + } if let Some((line_num, _)) = location { stub.push(atom_as_cell!(atom!(":"), 2)); - stub.push(str_loc_as_cell!(h + 6 + err_len)); + stub.push(str_loc_as_cell!(h + 6 + stub_addition_len)); stub.push(integer_as_cell!(Number::arena_from( line_num, &mut self.arena -- 2.54.0