/// Check if an name would shadow an existing symbol
Check if an name would shadow an existing symbol
Check if an name would shadow an existing symbol
pub fn check_shadowing(
        &mut self,
        file_no: usize,
        contract_no: Option<usize>,
        id: &pt::Identifier,
    ) {
        if builtin::is_reserved(&id.name) {
            self.diagnostics.push(ast::Diagnostic::warning(
                id.loc,
                format!("‘{}’ shadows name of a builtin", id.name.to_string()),
            ));
            return;
        }
        let mut s = self
            .symbols
            .get(&(file_no, contract_no, id.name.to_owned()));
        if s.is_none() {
            s = self.symbols.get(&(file_no, None, id.name.to_owned()));
        }
        match s {
            Some(ast::Symbol::Enum(loc, _)) => {
                self.diagnostics.push(ast::Diagnostic::warning_with_note(
                    id.loc,
                    format!("declaration of `{}' shadows enum definition", id.name),
                    *loc,
                    "previous definition of enum".to_string(),
                ));
            }
            Some(ast::Symbol::Struct(loc, _)) => {
                self.diagnostics.push(ast::Diagnostic::warning_with_note(
                    id.loc,
                    format!("declaration of `{}' shadows struct definition", id.name),
                    *loc,
                    "previous definition of struct".to_string(),
                ));
            }
            Some(ast::Symbol::Event(events)) => {
                let notes = events
                    .iter()
                    .map(|(pos, _)| ast::Note {
                        pos: *pos,
                        message: "previous definition of event".to_owned(),
                    })
                    .collect();
                self.diagnostics.push(ast::Diagnostic::warning_with_notes(
                    id.loc,
                    format!("declaration of `{}' shadows event definition", id.name),
                    notes,
                ));
            }
            Some(ast::Symbol::Function(v)) => {
                let notes = v
                    .iter()
                    .map(|(pos, _)| ast::Note {
                        pos: *pos,
                        message: "previous declaration of function".to_owned(),
                    })
                    .collect();
                self.diagnostics.push(ast::Diagnostic::warning_with_notes(
                    id.loc,
                    format!("declaration of ‘{}’ shadows function", id.name),
                    notes,
                ));
            }
            Some(ast::Symbol::Variable(loc, _, _)) => {
                self.diagnostics.push(ast::Diagnostic::warning_with_note(
                    id.loc,
                    format!("declaration of ‘{}’ shadows state variable", id.name),
                    *loc,
                    "previous declaration of state variable".to_string(),
                ));
            }
            Some(ast::Symbol::Contract(loc, _)) => {
                self.diagnostics.push(ast::Diagnostic::warning_with_note(
                    id.loc,
                    format!("declaration of ‘{}’ shadows contract name", id.name),
                    *loc,
                    "previous declaration of contract name".to_string(),
                ));
            }
            Some(ast::Symbol::Import(loc, _)) => {
                self.diagnostics.push(ast::Diagnostic::warning_with_note(
                    id.loc,
                    format!("declaration of ‘{}’ shadows import", id.name),
                    *loc,
                    "previous declaration of import".to_string(),
                ));
            }
            None => {}
        }
    }
pub fn check_shadowing ( & mut self , file_no : usize , contract_no : Option < usize > , id : & pt :: Identifier , ) { if builtin :: is_reserved ( & id . name ) { self . diagnostics . push ( ast :: Diagnostic :: warning ( id . loc , format ! ( " d am .to_ tring()), ) ) ; return ; } let mut s = self . symbols . get ( & ( file_no , contract_no , id . name . to_owned ( ) ) ) ; if s . is_none ( ) { s = self . symbols . get ( & ( file_no , None , id . name . to_owned ( ) ) ) ; } match s { Some ( ast :: Symbol :: Enum ( loc , _ ) ) => { self . diagnostics . push ( ast :: Diagnostic :: warning_with_note ( id . loc , format ! ( " " id name ) , * loc , " " . to_string ( ) , ) ) ; } Some ( ast :: Symbol :: Struct ( loc , _ ) ) => { self . diagnostics . push ( ast :: Diagnostic :: warning_with_note ( id . loc , format ! ( " " id name ) , * loc , " " . to_string ( ) , ) ) ; } Some ( ast :: Symbol :: Event ( events ) ) => { let notes = events . iter ( ) . map ( | ( pos , _ ) | ast :: Note { pos : * pos , message : " " . to_owned ( ) , } ) . collect ( ) ; self . diagnostics . push ( ast :: Diagnostic :: warning_with_notes ( id . loc , format ! ( " " id name ) , notes , ) ) ; } Some ( ast :: Symbol :: Function ( v ) ) => { let notes = v . iter ( ) . map ( | ( pos , _ ) | ast :: Note { pos : * pos , message : " " . to_owned ( ) , } ) . collect ( ) ; self . diagnostics . push ( ast :: Diagnostic :: warning_with_notes ( id . loc , format ! ( " d am ), notes , ) ) ; } Some ( ast :: Symbol :: Variable ( loc , _ , _ ) ) => { self . diagnostics . push ( ast :: Diagnostic :: warning_with_note ( id . loc , format ! ( " d am ), * loc , " " . to_string ( ) , ) ) ; } Some ( ast :: Symbol :: Contract ( loc , _ ) ) => { self . diagnostics . push ( ast :: Diagnostic :: warning_with_note ( id . loc , format ! ( " d am ), * loc , " " . to_string ( ) , ) ) ; } Some ( ast :: Symbol :: Import ( loc , _ ) ) => { self . diagnostics . push ( ast :: Diagnostic :: warning_with_note ( id . loc , format ! ( " d am ), * loc , " " . to_string ( ) , ) ) ; } None => { } } }
Check if an name would shadow an existing symbol
Check if an name would shadow an existing symbol
&mut self
file_no
usize
contract_no
Option<usize>
id
&pt::Identifier