Skip to content

Commit

Permalink
qualify module quantification errors better (#2685)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthom committed Dec 25, 2024
1 parent d287095 commit afc7b74
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/machine/system_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,17 +1311,22 @@ impl Machine {
fn quantification_to_module_name(
&mut self,
quantification: ModuleQuantification,
src: HeapCellValue,
) -> Result<Atom, MachineError> {
match quantification.specified() {
Some(module_name) => {
let module_name = self.machine_st.store(self.machine_st.deref(module_name));

if module_name.get_tag() == HeapCellValueTag::Atom {
Ok(cell_as_atom!(module_name))
} else {
Err(self.machine_st.type_error(ValidType::Atom, src))
}
read_heap_cell!(module_name,
(HeapCellValueTag::Atom, (module_name, _arity)) => {
Ok(module_name)
}
(HeapCellValueTag::Var) => {
Err(self.machine_st.instantiation_error())
}
_ => {
Err(self.machine_st.type_error(ValidType::Atom, module_name))
}
)
}
None => Ok(if let Some(load_context) = self.load_contexts.last() {
load_context.module
Expand Down Expand Up @@ -1389,7 +1394,7 @@ impl Machine {

let mut arity = arity + goal_arity;
let mut module_name = self
.quantification_to_module_name(module_quantification, self.machine_st.registers[1])
.quantification_to_module_name(module_quantification)
.map_err(|err| {
let stub = functor_stub(atom!("call"), arity);
self.machine_st.error_form(err, stub)
Expand All @@ -1410,10 +1415,7 @@ impl Machine {
self.machine_st.name_and_arity_from_heap(goal)
{
module_name = self
.quantification_to_module_name(
module_quantification,
self.machine_st.registers[1],
)
.quantification_to_module_name(module_quantification)
.unwrap_or(module_name);

arity -= goal_arity;
Expand Down

0 comments on commit afc7b74

Please sign in to comment.