ajust/add devlaration errors to be more standard compliant
This commit is contained in:
@@ -268,6 +268,26 @@ impl DomainError for HeapCellValue {
|
||||
}
|
||||
}
|
||||
|
||||
impl DomainError for FunctorStub {
|
||||
fn domain_error(
|
||||
self,
|
||||
machine_st: &mut MachineState,
|
||||
valid_type: DomainErrorType,
|
||||
) -> MachineError {
|
||||
let stub = functor!(
|
||||
atom!("domain_error"),
|
||||
[atom(valid_type.as_atom()), str(machine_st.heap.len(), 0)],
|
||||
[self]
|
||||
);
|
||||
|
||||
MachineError {
|
||||
stub,
|
||||
location: None,
|
||||
from: ErrorProvenance::Constructed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DomainError for Number {
|
||||
fn domain_error(self, machine_st: &mut MachineState, error: DomainErrorType) -> MachineError {
|
||||
let stub = functor!(
|
||||
@@ -731,6 +751,8 @@ pub enum DeclarationError {
|
||||
InvalidOpDeclSpecValue(Atom),
|
||||
InvalidOpDeclPrecType(Term),
|
||||
InvalidOpDeclPrecDomain(Fixnum),
|
||||
ShallNotCreate(Atom),
|
||||
ShallNotModify(Atom),
|
||||
}
|
||||
|
||||
impl From<ArithmeticError> for CompilationError {
|
||||
@@ -844,6 +866,7 @@ pub(crate) enum DomainErrorType {
|
||||
StreamOrAlias,
|
||||
OperatorSpecifier,
|
||||
OperatorPriority,
|
||||
Declaration,
|
||||
}
|
||||
|
||||
impl DomainErrorType {
|
||||
@@ -857,6 +880,7 @@ impl DomainErrorType {
|
||||
DomainErrorType::StreamOrAlias => atom!("stream_or_alias"),
|
||||
DomainErrorType::OperatorSpecifier => atom!("operator_specifier"),
|
||||
DomainErrorType::OperatorPriority => atom!("operator_priority"),
|
||||
DomainErrorType::Declaration => atom!("declaration"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -986,7 +986,7 @@ impl MachineState {
|
||||
atom_as_cell!(atom!("todo_insert_invalid_term_here")),
|
||||
),
|
||||
DeclarationError::InvalidDecl(name, arity) => {
|
||||
self.existence_error(ExistenceError::Declaration(name, arity))
|
||||
self.domain_error(DomainErrorType::Declaration, functor_stub(name, arity))
|
||||
}
|
||||
DeclarationError::InvalidOpDeclNameType(_term) => self.type_error(
|
||||
ValidType::List,
|
||||
@@ -1006,6 +1006,12 @@ impl MachineState {
|
||||
DeclarationError::InvalidOpDeclPrecDomain(num) => {
|
||||
self.domain_error(DomainErrorType::OperatorPriority, fixnum_as_cell!(num))
|
||||
}
|
||||
DeclarationError::ShallNotCreate(atom) => {
|
||||
self.permission_error(Permission::Create, atom!("operator"), atom)
|
||||
}
|
||||
DeclarationError::ShallNotModify(atom) => {
|
||||
self.permission_error(Permission::Modify, atom!("operator"), atom)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,24 @@ fn setup_op_decl(mut terms: Vec<Term>, atom_tbl: &AtomTable) -> Result<OpDecl, C
|
||||
}
|
||||
};
|
||||
|
||||
if name == "[]" || name == "{}" {
|
||||
return Err(CompilationError::InvalidDecl(
|
||||
DeclarationError::ShallNotCreate(name),
|
||||
));
|
||||
}
|
||||
|
||||
if name == "," {
|
||||
return Err(CompilationError::InvalidDecl(
|
||||
DeclarationError::ShallNotModify(name),
|
||||
));
|
||||
}
|
||||
|
||||
if name == "|" && (prec < 1001 || !spec.is_infix()) {
|
||||
return Err(CompilationError::InvalidDecl(
|
||||
DeclarationError::ShallNotCreate(name),
|
||||
));
|
||||
}
|
||||
|
||||
Ok(to_op_decl(prec, spec, name))
|
||||
}
|
||||
|
||||
|
||||
1
tests-pl/invalid_decl12.pl
Normal file
1
tests-pl/invalid_decl12.pl
Normal file
@@ -0,0 +1 @@
|
||||
:- op(500, xfy, {}).
|
||||
1
tests-pl/invalid_decl13.pl
Normal file
1
tests-pl/invalid_decl13.pl
Normal file
@@ -0,0 +1 @@
|
||||
:- op(500, xfy, [{}]).
|
||||
1
tests-pl/invalid_decl14.pl
Normal file
1
tests-pl/invalid_decl14.pl
Normal file
@@ -0,0 +1 @@
|
||||
:- op(1000, xfy, '|').
|
||||
1
tests-pl/invalid_decl15.pl
Normal file
1
tests-pl/invalid_decl15.pl
Normal file
@@ -0,0 +1 @@
|
||||
:- op(1150, fx, '|').
|
||||
1
tests-pl/invalid_decl16.pl
Normal file
1
tests-pl/invalid_decl16.pl
Normal file
@@ -0,0 +1 @@
|
||||
:- op(500, yfx, ',').
|
||||
@@ -18,13 +18,13 @@ $ scryer-prolog -f --no-add-history tests-pl/invalid_decl3.pl -g halt
|
||||
|
||||
```trycmd
|
||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl4.pl -g halt
|
||||
error(existence_error(declaration,op/4),load/1).
|
||||
error(domain_error(declaration,op/4),load/1).
|
||||
|
||||
```
|
||||
|
||||
```trycmd
|
||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl5.pl -g halt
|
||||
error(existence_error(declaration,(;)/2),load/1).
|
||||
error(domain_error(declaration,(;)/2),load/1).
|
||||
|
||||
```
|
||||
|
||||
@@ -66,3 +66,33 @@ The following test doesn't appear to terminate so its moved to a block quote for
|
||||
> % Warning: singleton variables Var at line 0 of invalid_decl11.pl
|
||||
> error(instantiation_error,load/1).
|
||||
> ```
|
||||
|
||||
```trycmd
|
||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl12.pl -g halt
|
||||
error(permission_error(create,operator,{}),load/1).
|
||||
|
||||
```
|
||||
|
||||
```trycmd
|
||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl13.pl -g halt
|
||||
error(permission_error(create,operator,{}),load/1).
|
||||
|
||||
```
|
||||
|
||||
```trycmd
|
||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl14.pl -g halt
|
||||
error(permission_error(create,operator,'|'),load/1).
|
||||
|
||||
```
|
||||
|
||||
```trycmd
|
||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl15.pl -g halt
|
||||
error(permission_error(create,operator,'|'),load/1).
|
||||
|
||||
```
|
||||
|
||||
```trycmd
|
||||
$ scryer-prolog -f --no-add-history tests-pl/invalid_decl16.pl -g halt
|
||||
error(permission_error(modify,operator,','),load/1).
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user