public final void checkMultiExpressions ( Tuple < Expr > expressions , Environment environment , Tuple < Type > expected ) { for ( int i = 0 , j = 0 ; i != expressions . size ( ) ; ++ i ) { Expr expression = expressions . get ( i ) ; switch ( expression . getOpcode ( ) ) { case EXPR_invoke : { Tuple < Type > results = checkInvoke ( ( Expr . Invoke ) expression , environment ) ; if ( results == null ) { // Some type error occurred upstream, therefore make conservative assumption j = j + 1 ; } else { // FIXME: THIS LOOP IS UGLY for ( int k = 0 ; k != results . size ( ) ; ++ k ) { checkIsSubtype ( expected . get ( j + k ) , results . get ( k ) , environment , expression ) ; } j = j + results . size ( ) ; } break ; } case EXPR_indirectinvoke : { Tuple < Type > results = checkIndirectInvoke ( ( Expr . IndirectInvoke ) expression , environment ) ; if ( results == null ) { // Some type error occurred upstream, therefore make conservative assumption j = j + 1 ; } else { // FIXME: THIS LOOP IS UGLY for ( int k = 0 ; k != results . size ( ) ; ++ k ) { checkIsSubtype ( expected . get ( j + k ) , results . get ( k ) , environment , expression ) ; } j = j + results . size ( ) ; } break ; } default : SemanticType type = checkExpression ( expression , environment ) ; // if ( ( expected . size ( ) - j ) < 1 ) { syntaxError ( expression , TOO_MANY_RETURNS ) ; } else if ( ( i + 1 ) == expressions . size ( ) && ( expected . size ( ) - j ) > 1 ) { syntaxError ( expression , INSUFFICIENT_RETURNS ) ; } else { checkIsSubtype ( expected . get ( j ) , type , environment , expression ) ; } j = j + 1 ; } } }
Type check a sequence of zero or more multi - expressions assuming a given initial environment . A multi - expression is one which may have multiple return values . There are relatively few situations where this can arise particular assignments and return statements . This returns a sequence of one or more pairs each of which corresponds to a single return for a given expression . Thus each expression generates one or more pairs in the result .