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:
Jakub Žádník 2022-02-21 23:05:20 +02:00 committed by GitHub
parent 6d4784a7c1
commit 359bb6eebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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();

View File

@ -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();