mirror of
https://github.com/nushell/nushell.git
synced 2025-01-23 06:39:17 +01:00
Look up predecl only in the working set (#4592)
Previously, the parser tried to look up the predecl also in the permanent state and if a definition with that name already existed, it would try to update it, which is illegal.
This commit is contained in:
parent
6d4784a7c1
commit
359bb6eebe
@ -331,7 +331,7 @@ pub fn parse_def(
|
||||
if let (Some(name), Some(mut signature), Some(block_id)) =
|
||||
(&name_expr.as_string(), sig.as_signature(), block.as_block())
|
||||
{
|
||||
if let Some(decl_id) = working_set.find_decl(name.as_bytes()) {
|
||||
if let Some(decl_id) = working_set.find_predecl(name.as_bytes()) {
|
||||
let declaration = working_set.get_decl_mut(decl_id);
|
||||
|
||||
signature.name = name.clone();
|
||||
@ -430,7 +430,7 @@ pub fn parse_extern(
|
||||
|
||||
if let (Some(name_expr), Some(sig)) = (name_expr, sig) {
|
||||
if let (Some(name), Some(mut signature)) = (&name_expr.as_string(), sig.as_signature()) {
|
||||
if let Some(decl_id) = working_set.find_decl(name.as_bytes()) {
|
||||
if let Some(decl_id) = working_set.find_predecl(name.as_bytes()) {
|
||||
let declaration = working_set.get_decl_mut(decl_id);
|
||||
|
||||
signature.name = name.clone();
|
||||
|
@ -999,6 +999,16 @@ impl<'a> StateWorkingSet<'a> {
|
||||
self.delta.exit_scope();
|
||||
}
|
||||
|
||||
pub fn find_predecl(&self, name: &[u8]) -> Option<DeclId> {
|
||||
for scope in self.delta.scope.iter().rev() {
|
||||
if let Some(decl_id) = scope.predecls.get(name) {
|
||||
return Some(*decl_id);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
pub fn find_decl(&self, name: &[u8]) -> Option<DeclId> {
|
||||
let mut visibility: Visibility = Visibility::new();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user