@@ -989,7 +989,6 @@ impl PythonArchEval {
989989 diagnostics : & mut Vec < Diagnostic > ,
990990 ) {
991991 if let Some ( returns_ann) = func_stmt. returns . as_ref ( ) {
992- let file_sym = func_sym. borrow ( ) . get_file ( ) . and_then ( |file_weak| file_weak. upgrade ( ) ) ;
993992 let mut deps = vec ! [ vec![ ] , vec![ ] ] ;
994993 let ( mut evaluations, diags) = Evaluation :: eval_from_ast (
995994 session,
@@ -999,6 +998,22 @@ impl PythonArchEval {
999998 true ,
1000999 & mut deps,
10011000 ) ;
1001+ // Check for type annotation `typing.Self`, if so, return a `self` evaluation
1002+ // And give it priority over other evaluations
1003+ if evaluations. iter ( ) . any ( |evaluation|
1004+ Symbol :: follow_ref (
1005+ & evaluation. symbol . get_symbol ( session, & mut None , diagnostics, None ) ,
1006+ session,
1007+ & mut None ,
1008+ false ,
1009+ false ,
1010+ Some ( ( vec ! [ Sy !( "typing" ) ] , vec ! [ Sy !( "Self" ) ] ) ) ,
1011+ None
1012+ ) . len ( ) > 0
1013+ ) {
1014+ func_sym. borrow_mut ( ) . set_evaluations ( vec ! [ Evaluation :: new_self( ) ] ) ;
1015+ return ;
1016+ }
10021017 for eval in evaluations. iter_mut ( ) { //as this is an evaluation, we need to set the instance to true
10031018 match eval. symbol . get_mut_symbol_ptr ( ) {
10041019 EvaluationSymbolPtr :: WEAK ( sym_weak) => {
@@ -1007,23 +1022,10 @@ impl PythonArchEval {
10071022 _ => { }
10081023 }
10091024 }
1010- if file_sym. is_some ( ) {
1011- Symbol :: insert_dependencies ( & file_sym. as_ref ( ) . unwrap ( ) , & mut deps, BuildSteps :: ARCH_EVAL ) ;
1025+ if let Some ( file_sym) = func_sym . borrow ( ) . get_file ( ) . and_then ( |file_weak| file_weak . upgrade ( ) ) . as_ref ( ) {
1026+ Symbol :: insert_dependencies ( file_sym, & mut deps, BuildSteps :: ARCH_EVAL ) ;
10121027 }
10131028 diagnostics. extend ( diags) ;
1014- // Check for type annotation `typing.Self`, if so, return a `self` evaluation
1015- let final_evaluations = evaluations. into_iter ( ) . map ( |eval|{
1016- let sym_ptrs = Symbol :: follow_ref ( & eval. symbol . get_symbol ( session, & mut None , diagnostics, None ) , session, & mut None , false , false , None , None ) ;
1017- for sym_ptr in sym_ptrs. iter ( ) {
1018- let EvaluationSymbolPtr :: WEAK ( sym_weak) = sym_ptr else { continue } ;
1019- let Some ( sym_rc) = sym_weak. weak . upgrade ( ) else { continue } ;
1020- if sym_rc. borrow ( ) . match_tree_from_any_entry ( session, & ( vec ! [ Sy !( "typing" ) ] , vec ! [ Sy !( "Self" ) ] ) ) {
1021- return Evaluation :: new_self ( ) ;
1022- }
1023- }
1024- eval
1025- } ) . collect :: < Vec < _ > > ( ) ;
1026- func_sym. borrow_mut ( ) . set_evaluations ( final_evaluations) ;
10271029 }
10281030 }
10291031
0 commit comments