public void checkFunctionOrMethodDeclaration ( Decl . FunctionOrMethod d ) { // Construct initial environment Environment environment = new Environment ( ) ; // Update environment so this within declared lifetimes environment = FlowTypeUtils . declareThisWithin ( d , environment ) ; // Check parameters and returns are not empty (i.e. are not equivalent // to void, as this is non-sensical). checkVariableDeclarations ( d . getParameters ( ) , environment ) ; checkVariableDeclarations ( d . getReturns ( ) , environment ) ; // Check any preconditions (i.e. requires clauses) provided. checkConditions ( d . getRequires ( ) , true , environment ) ; // Check any postconditions (i.e. ensures clauses) provided. checkConditions ( d . getEnsures ( ) , true , environment ) ; // FIXME: Add the "this" lifetime if ( d . getModifiers ( ) . match ( Modifier . Native . class ) == null ) { // Create scope representing this declaration EnclosingScope scope = new FunctionOrMethodScope ( d ) ; // Check type information throughout all statements in body. Environment last = checkBlock ( d . getBody ( ) , environment , scope ) ; // Check return value checkReturnValue ( d , last ) ; } else { // NOTE: we obviously don't need to check the body of a native function or // method. Attempting to do so causes problems because checkReturnValue will // fail. } }
Type check a given function or method declaration .