]> Repositorios git - scryer-prolog.git/commitdiff
qualify module quantification errors better (#2685)
authorMark Thom <[email protected]>
Wed, 25 Dec 2024 20:23:21 +0000 (12:23 -0800)
committerMark Thom <[email protected]>
Wed, 25 Dec 2024 20:25:01 +0000 (12:25 -0800)
src/machine/system_calls.rs

index 1069b8d4b71097411a3943e9e37dfa38228e32f2..8d80926b9d4afc8c28b3763a1d5a62123a9db00a 100644 (file)
@@ -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
@@ -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)
@@ -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;