Skip to content

Commit

Permalink
Modified expression resolver to take annotated symbols into account
Browse files Browse the repository at this point in the history
  • Loading branch information
SpontanCombust committed Aug 22, 2024
1 parent 0eb9bc5 commit 0eb0562
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ type Scope = HashMap<Key, SymbolPathBuf>;
/// e.g. a member var can be used without `this` keyword and thus becomes ambiguous
/// without the context of inherited properties, local vars and global constants (enum variants).
/// Names on each deeper scope layer can overshadow the same name from higher layers.
///
/// Methods that have been `@wrap`ed or `@replace`d still produce path to the original symbol.
#[derive(Debug, Clone)]
pub struct UnqualifiedNameLookup {
stack: Vec<Scope>
Expand Down
32 changes: 31 additions & 1 deletion crates/analysis/src/utils/visitors/expr_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ impl<'a> ExpressionEvaluator<'a> {
SymbolVariant::MemberFuncWrapper(s) => s.return_type_path.clone().into(),
SymbolVariant::MemberVarInjector(s) => s.type_path.clone().into(),
SymbolVariant::WrappedMethod(s) => {
// we don't have to look at the annotation chain
// as the function annotated with `@wrapMethod` in which wrappedMethod() is used
// should have the same return type as the original or replaced function

self.symtab_marcher
.get_symbol(s.path().parent().unwrap_or_default())
.and_then(|v| v.try_as_member_func_wrapper_ref())
Expand Down Expand Up @@ -210,11 +214,37 @@ impl SyntaxNodeVisitor for ExpressionEvaluator<'_> {
SymbolCategory::Data
};

let ident_path = self.unl_payload.borrow()
let mut ident_path = self.unl_payload.borrow()
.get(&name, ident_category)
.map(|p| p.to_owned())
.unwrap_or(SymbolPathBuf::new(&name, ident_category));

// resolve function calls to annotated symbols if they exist
match self.symtab_marcher.get_symbol(&ident_path) {
Some(SymbolVariant::GlobalFunc(s)) => {
ident_path = self.symtab_marcher
.annotation_chain_for_global_callable(s.path())
.next()
.map(|v| v.path_ref().to_owned())
.unwrap_or(ident_path);
},
Some(SymbolVariant::MemberFunc(s)) => {
ident_path = self.symtab_marcher
.annotation_chain_for_member_callable(s.path())
.next()
.map(|v| v.path_ref().to_owned())
.unwrap_or(ident_path);
},
Some(SymbolVariant::Event(s)) => {
ident_path = self.symtab_marcher
.annotation_chain_for_member_callable(s.path())
.next()
.map(|v| v.path_ref().to_owned())
.unwrap_or(ident_path);
}
_ => {}
}

self.push(ident_path, ctx.top());
}

Expand Down

0 comments on commit 0eb0562

Please sign in to comment.