@@ -977,7 +977,6 @@ impl PythonArchEval {
977977 diagnostics : & mut Vec < Diagnostic > ,
978978 ) {
979979 if let Some ( returns_ann) = func_stmt. returns . as_ref ( ) {
980- let file_sym = func_sym. borrow ( ) . get_file ( ) . and_then ( |file_weak| file_weak. upgrade ( ) ) ;
981980 let mut deps = vec ! [ vec![ ] , vec![ ] ] ;
982981 let ( mut evaluations, diags) = Evaluation :: eval_from_ast (
983982 session,
@@ -987,6 +986,22 @@ impl PythonArchEval {
987986 true ,
988987 & mut deps,
989988 ) ;
989+ // Check for type annotation `typing.Self`, if so, return a `self` evaluation
990+ // And give it priority over other evaluations
991+ if evaluations. iter ( ) . any ( |evaluation|
992+ Symbol :: follow_ref (
993+ & evaluation. symbol . get_symbol ( session, & mut None , diagnostics, None ) ,
994+ session,
995+ & mut None ,
996+ false ,
997+ false ,
998+ Some ( ( vec ! [ Sy !( "typing" ) ] , vec ! [ Sy !( "Self" ) ] ) ) ,
999+ None
1000+ ) . len ( ) > 0
1001+ ) {
1002+ func_sym. borrow_mut ( ) . set_evaluations ( vec ! [ Evaluation :: new_self( ) ] ) ;
1003+ return ;
1004+ }
9901005 for eval in evaluations. iter_mut ( ) { //as this is an evaluation, we need to set the instance to true
9911006 match eval. symbol . get_mut_symbol_ptr ( ) {
9921007 EvaluationSymbolPtr :: WEAK ( sym_weak) => {
@@ -995,23 +1010,10 @@ impl PythonArchEval {
9951010 _ => { }
9961011 }
9971012 }
998- if file_sym. is_some ( ) {
999- Symbol :: insert_dependencies ( & file_sym. as_ref ( ) . unwrap ( ) , & mut deps, BuildSteps :: ARCH_EVAL ) ;
1013+ if let Some ( file_sym) = func_sym . borrow ( ) . get_file ( ) . and_then ( |file_weak| file_weak . upgrade ( ) ) . as_ref ( ) {
1014+ Symbol :: insert_dependencies ( file_sym, & mut deps, BuildSteps :: ARCH_EVAL ) ;
10001015 }
10011016 diagnostics. extend ( diags) ;
1002- // Check for type annotation `typing.Self`, if so, return a `self` evaluation
1003- let final_evaluations = evaluations. into_iter ( ) . map ( |eval|{
1004- let sym_ptrs = Symbol :: follow_ref ( & eval. symbol . get_symbol ( session, & mut None , diagnostics, None ) , session, & mut None , false , false , None , None ) ;
1005- for sym_ptr in sym_ptrs. iter ( ) {
1006- let EvaluationSymbolPtr :: WEAK ( sym_weak) = sym_ptr else { continue } ;
1007- let Some ( sym_rc) = sym_weak. weak . upgrade ( ) else { continue } ;
1008- if sym_rc. borrow ( ) . match_tree_from_any_entry ( session, & ( vec ! [ Sy !( "typing" ) ] , vec ! [ Sy !( "Self" ) ] ) ) {
1009- return Evaluation :: new_self ( ) ;
1010- }
1011- }
1012- eval
1013- } ) . collect :: < Vec < _ > > ( ) ;
1014- func_sym. borrow_mut ( ) . set_evaluations ( final_evaluations) ;
10151017 }
10161018 }
10171019
0 commit comments