From: Mark Thom Date: Sat, 4 Dec 2021 04:18:13 +0000 (-0700) Subject: fix bug in error_form X-Git-Tag: v0.9.0^2~110 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=4cde8cd5015057e01901be241ddf802100327df1;p=scryer-prolog.git fix bug in error_form --- 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