mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 13:26:01 +02:00
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:
@ -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> {
|
||||
|
Reference in New Issue
Block a user