Fix panic on double def; Tests; Double def error

* Fixes a panic with defining two commands with the same name caused by
  declaration not found after predeclaration.
* Adds a new error if a custom command is defined more than once in one
  block.
* Add some tests
This commit is contained in:
Jakub Žádník
2021-10-01 23:16:27 +03:00
parent 2af8116f50
commit 25b05dec9e
4 changed files with 18 additions and 12 deletions

View File

@ -311,17 +311,13 @@ impl<'a> StateWorkingSet<'a> {
decl_id
}
pub fn add_predecl(&mut self, decl: Box<dyn Command>) {
pub fn add_predecl(&mut self, decl: Box<dyn Command>) -> Option<DeclId> {
let name = decl.name().as_bytes().to_vec();
self.delta.decls.push(decl);
let decl_id = self.num_decls() - 1;
self.delta.predecls.insert(name, decl_id);
}
pub fn find_predecl(&mut self, name: &[u8]) -> Option<DeclId> {
self.delta.predecls.get(name).copied()
self.delta.predecls.insert(name, decl_id)
}
pub fn merge_predecl(&mut self, name: &[u8]) -> Option<DeclId> {