Skip to content

Commit

Permalink
add missing permission error in compile_assert (#2271)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthom committed Jan 4, 2024
1 parent ec97ee5 commit 851ea2c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/machine/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions src/machine/machine_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,13 @@ impl MachineState {
.into_iter()
.collect::<MachineStub>(),
),
SessionError::CannotOverwriteStaticProcedure(key) => self.permission_error(
Permission::Modify,
atom!("static_procedure"),
functor_stub(key.0, key.1)
.into_iter()
.collect::<MachineStub>(),
),
SessionError::CannotOverwriteBuiltInModule(module) => {
self.permission_error(Permission::Modify, atom!("static_module"), module)
}
Expand Down Expand Up @@ -1005,6 +1012,7 @@ pub enum SessionError {
CompilationError(CompilationError),
CannotOverwriteBuiltIn(PredicateKey),
CannotOverwriteBuiltInModule(Atom),
CannotOverwriteStaticProcedure(PredicateKey),
ExistenceError(ExistenceError),
ModuleDoesNotContainExport(Atom, PredicateKey),
ModuleCannotImportSelf(Atom),
Expand Down

0 comments on commit 851ea2c

Please sign in to comment.