-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support implementing trait functions in
impl
blocks
- Loading branch information
Showing
54 changed files
with
1,899 additions
and
965 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use indexmap::map::Entry; | ||
use indexmap::IndexMap; | ||
use smol_str::SmolStr; | ||
|
||
use crate::context::{Analysis, AnalyzerContext}; | ||
use crate::namespace::items::{Function, FunctionId, ImplId}; | ||
use crate::namespace::scopes::ItemScope; | ||
use crate::namespace::types::TypeDowncast; | ||
use crate::AnalyzerDb; | ||
use std::rc::Rc; | ||
|
||
pub fn impl_all_functions(db: &dyn AnalyzerDb, impl_: ImplId) -> Rc<[FunctionId]> { | ||
let impl_data = impl_.data(db); | ||
impl_data | ||
.ast | ||
.kind | ||
.functions | ||
.iter() | ||
.map(|node| { | ||
db.intern_function(Rc::new(Function::new( | ||
db, | ||
node, | ||
impl_.receiver(db).as_class(), | ||
impl_data.module, | ||
))) | ||
}) | ||
.collect() | ||
} | ||
|
||
pub fn impl_function_map( | ||
db: &dyn AnalyzerDb, | ||
impl_: ImplId, | ||
) -> Analysis<Rc<IndexMap<SmolStr, FunctionId>>> { | ||
let scope = ItemScope::new(db, impl_.module(db)); | ||
let mut map = IndexMap::<SmolStr, FunctionId>::new(); | ||
|
||
for func in db.impl_all_functions(impl_).iter() { | ||
let def_name = func.name(db); | ||
|
||
match map.entry(def_name) { | ||
Entry::Occupied(entry) => { | ||
scope.duplicate_name_error( | ||
"duplicate function names in `impl` block", | ||
entry.key(), | ||
entry.get().name_span(db), | ||
func.name_span(db), | ||
); | ||
} | ||
Entry::Vacant(entry) => { | ||
entry.insert(*func); | ||
} | ||
} | ||
} | ||
Analysis::new(Rc::new(map), scope.diagnostics.take().into()) | ||
} |
Oops, something went wrong.