From 851ea2c45b490093e5ab0761fac29005ff9001ae Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 4 Jan 2024 13:53:46 -0700 Subject: [PATCH] add missing permission error in compile_assert (#2271) --- src/machine/loader.rs | 14 ++++++++++---- src/machine/machine_errors.rs | 8 ++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/machine/loader.rs b/src/machine/loader.rs index fb9b22bb..ae2fad2b 100644 --- a/src/machine/loader.rs +++ b/src/machine/loader.rs @@ -1972,11 +1972,13 @@ impl Machine { _ => CompilationTarget::Module(module_name), }; - let stub_gen = || match append_or_prepend { - AppendOrPrepend::Append => functor_stub(atom!("assertz"), 1), - AppendOrPrepend::Prepend => functor_stub(atom!("asserta"), 1), + let key = match append_or_prepend { + AppendOrPrepend::Append => (atom!("assertz"), 1), + AppendOrPrepend::Prepend => (atom!("asserta"), 1), }; + let stub_gen = || functor_stub(key.0, key.1); + let head = self.deref_register(2); if head.is_var() { @@ -2015,7 +2017,11 @@ impl Machine { .map(|code_idx| code_idx.get_tag()) .unwrap_or(IndexPtrTag::DynamicUndefined); - idx_tag == IndexPtrTag::DynamicUndefined || idx_tag == IndexPtrTag::Undefined + if idx_tag == IndexPtrTag::Index { + return Err(SessionError::CannotOverwriteStaticProcedure((name, arity))); + } else { + idx_tag == IndexPtrTag::Undefined || idx_tag == IndexPtrTag::DynamicUndefined + } } else if is_builtin { return Err(SessionError::CannotOverwriteBuiltIn((name, arity))); } else { diff --git a/src/machine/machine_errors.rs b/src/machine/machine_errors.rs index 49d56510..c2cbb405 100644 --- a/src/machine/machine_errors.rs +++ b/src/machine/machine_errors.rs @@ -488,6 +488,13 @@ impl MachineState { .into_iter() .collect::(), ), + SessionError::CannotOverwriteStaticProcedure(key) => self.permission_error( + Permission::Modify, + atom!("static_procedure"), + functor_stub(key.0, key.1) + .into_iter() + .collect::(), + ), SessionError::CannotOverwriteBuiltInModule(module) => { self.permission_error(Permission::Modify, atom!("static_module"), module) } @@ -1005,6 +1012,7 @@ pub enum SessionError { CompilationError(CompilationError), CannotOverwriteBuiltIn(PredicateKey), CannotOverwriteBuiltInModule(Atom), + CannotOverwriteStaticProcedure(PredicateKey), ExistenceError(ExistenceError), ModuleDoesNotContainExport(Atom, PredicateKey), ModuleCannotImportSelf(Atom), -- 2.54.0