protect imported predicates from being overwritten (re: issue #28)

This commit is contained in:
Mark Thom
2018-04-23 15:55:53 -06:00
parent b87d599b14
commit a891b9327c
2 changed files with 3 additions and 5 deletions

View File

@@ -267,7 +267,7 @@ impl fmt::Display for EvalError {
&EvalError::ModuleDoesNotContainExport => write!(f, "module does not contain claimed export."), &EvalError::ModuleDoesNotContainExport => write!(f, "module does not contain claimed export."),
&EvalError::QueryFailure => write!(f, "false."), &EvalError::QueryFailure => write!(f, "false."),
&EvalError::QueryFailureWithException(ref e) => write!(f, "{}", error_string(e)), &EvalError::QueryFailureWithException(ref e) => write!(f, "{}", error_string(e)),
&EvalError::ImpermissibleEntry(ref msg) => write!(f, "cannot overwrite builtin {}.", msg), &EvalError::ImpermissibleEntry(ref msg) => write!(f, "cannot overwrite {}.", msg),
&EvalError::OpIsInfixAndPostFix => &EvalError::OpIsInfixAndPostFix =>
write!(f, "cannot define an op to be both postfix and infix."), write!(f, "cannot define an op to be both postfix and infix."),
&EvalError::NamelessEntry => write!(f, "the predicate head is not an atom or clause."), &EvalError::NamelessEntry => write!(f, "the predicate head is not an atom or clause."),

View File

@@ -190,12 +190,10 @@ impl Machine {
-> EvalSession -> EvalSession
{ {
match self.code_dir.get(&(name.clone(), arity)) { match self.code_dir.get(&(name.clone(), arity)) {
Some(&CodeIndex (ref idx)) => Some(&CodeIndex (ref idx)) if idx.borrow().1 != clause_name!("user") =>
if idx.borrow().1 == clause_name!("builtin") {
return EvalSession::from(EvalError::ImpermissibleEntry(format!("{}/{}", return EvalSession::from(EvalError::ImpermissibleEntry(format!("{}/{}",
name, name,
arity))) arity))),
},
_ => {} _ => {}
}; };