@@ -20,41 +20,42 @@ namespace Microsoft.Python.Analysis {
2020 public static class PythonWalkerExtensions {
2121 public static bool WalkIfWithSystemConditions ( this IfStatement node , PythonWalker walker , PythonLanguageVersion languageVersion , bool isWindows ) {
2222 // System version, platform and os.path specializations
23- var someRecognized = false ;
23+ var executeElse = false ;
2424 foreach ( var test in node . Tests ) {
25+
2526 var result = test . TryHandleSysVersionInfo ( languageVersion ) ;
26- if ( result != ConditionTestResult . Unrecognized ) {
27- if ( result == ConditionTestResult . WalkBody ) {
28- test . Walk ( walker ) ;
29- } else {
30- node . ElseStatement ? . Walk ( walker ) ;
27+ if ( result == ConditionTestResult . Unrecognized ) {
28+ result = test . TryHandleSysPlatform ( isWindows ) ;
29+ if ( result == ConditionTestResult . Unrecognized ) {
30+ result = test . TryHandleOsPath ( isWindows ) ;
3131 }
32- someRecognized = true ;
33- continue ;
3432 }
3533
36- result = test . TryHandleSysPlatform ( isWindows ) ;
37- if ( result != ConditionTestResult . Unrecognized ) {
38- if ( result == ConditionTestResult . WalkBody ) {
34+ // If condition is satisfied, walk the corresponding block and
35+ // return false indicating that statement should not be walked again.
36+ // If condition is false or was not recognized, continue but remember
37+ // if we need to execute final else clause.
38+ switch ( result ) {
39+ case ConditionTestResult . WalkBody :
3940 test . Walk ( walker ) ;
40- } else {
41- node . ElseStatement ? . Walk ( walker ) ;
42- }
43- someRecognized = true ;
44- continue ;
41+ return false ; // We only need to execute one of the clauses.
42+ case ConditionTestResult . DontWalkBody :
43+ // If condition is false, continue but remember
44+ // if we may need to execute the final else clause.
45+ executeElse = true ;
46+ break ;
47+ case ConditionTestResult . Unrecognized :
48+ continue ; // See if other conditions may work.
4549 }
50+ }
4651
47- result = test . TryHandleOsPath ( isWindows ) ;
48- if ( result != ConditionTestResult . Unrecognized ) {
49- if ( result == ConditionTestResult . WalkBody ) {
50- test . Walk ( walker ) ;
51- } else {
52- node . ElseStatement ? . Walk ( walker ) ;
53- }
54- return false ; // Execute only one condition.
55- }
52+ if ( executeElse ) {
53+ node . ElseStatement ? . Walk ( walker ) ;
54+ return false ;
5655 }
57- return ! someRecognized ;
56+
57+ // We didn't walk anything, so me caller do their own thing.
58+ return true ;
5859 }
5960 }
6061}
0 commit comments