@@ -60,9 +60,7 @@ public ExtractMethodResult GetExtractionResult() {
6060 bool isStaticMethod = false , isClassMethod = false ;
6161 var parameters = new List < Parameter > ( ) ;
6262 NameExpression selfParam = null ;
63- if ( _targetScope is ClassDefinition ) {
64- var fromScope = _scopes [ _scopes . Count - 1 ] as FunctionDefinition ;
65- Debug . Assert ( fromScope != null ) ; // we don't allow extracting from classes, so we have to be coming from a function
63+ if ( _targetScope is ClassDefinition && _scopes [ _scopes . Count - 1 ] is FunctionDefinition fromScope ) {
6664 foreach ( var name in ( fromScope ? . Decorators ? . Decorators ) . MaybeEnumerate ( ) . ExcludeDefault ( ) . OfType < NameExpression > ( ) ) {
6765 if ( name . Name == "staticmethod" ) {
6866 isStaticMethod = true ;
@@ -230,15 +228,12 @@ public ExtractMethodResult GetExtractionResult() {
230228 newCall . Append ( "await " ) ;
231229 }
232230
233- if ( _targetScope is ClassDefinition ) {
234- var fromScope = _scopes [ _scopes . Count - 1 ] as FunctionDefinition ;
235- Debug . Assert ( fromScope != null ) ; // we don't allow extracting from classes, so we have to be coming from a function
236-
231+ if ( _targetScope is ClassDefinition && _scopes [ _scopes . Count - 1 ] is FunctionDefinition fromScope2 ) {
237232 if ( isStaticMethod ) {
238233 newCall . Append ( _targetScope . Name ) ;
239234 newCall . Append ( '.' ) ;
240- } else if ( fromScope != null && fromScope . Parameters . Length > 0 ) {
241- newCall . Append ( fromScope . Parameters [ 0 ] . Name ) ;
235+ } else if ( fromScope2 != null && fromScope2 . Parameters . Length > 0 ) {
236+ newCall . Append ( fromScope2 . Parameters [ 0 ] . Name ) ;
242237 newCall . Append ( '.' ) ;
243238 }
244239 }
0 commit comments