Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision 33a7b6db7e7a3b3fa85ef51cb227fdc43223b1fd)
+++ src/GenPoly/Box.cc	(revision d9fa60af0bc172d6842f414cb608e0615d3582a5)
@@ -98,5 +98,5 @@
 			void passArgTypeVars( ApplicationExpr *appExpr, Type *parmType, Type *argBaseType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars, std::set< std::string > &seenTypes );
 			/// passes extra type parameters into a polymorphic function application
-			void passTypeVars( ApplicationExpr *appExpr, ReferenceToType *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars );
+			void passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars );
 			/// wraps a function application with a new temporary for the out-parameter return value
 			Expression *addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg );
@@ -107,5 +107,5 @@
 			Type *replaceWithConcrete( ApplicationExpr *appExpr, Type *type, bool doClone = true );
 			/// wraps a function application returning a polymorphic type with a new temporary for the out-parameter return value
-			Expression *addDynRetParam( ApplicationExpr *appExpr, FunctionType *function, ReferenceToType *polyType, std::list< Expression *>::iterator &arg );
+			Expression *addDynRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *polyType, std::list< Expression *>::iterator &arg );
 			Expression *applyAdapter( ApplicationExpr *appExpr, FunctionType *function, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars );
 			void boxParam( Type *formal, Expression *&arg, const TyVarMap &exprTyVars );
@@ -769,5 +769,5 @@
 		}
 
-		void Pass1::passTypeVars( ApplicationExpr *appExpr, ReferenceToType *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
+		void Pass1::passTypeVars( ApplicationExpr *appExpr, Type *polyRetType, std::list< Expression *>::iterator &arg, const TyVarMap &exprTyVars ) {
 			// pass size/align for type variables
 			for ( TyVarMap::const_iterator tyParm = exprTyVars.begin(); tyParm != exprTyVars.end(); ++tyParm ) {
@@ -818,14 +818,8 @@
 
 		Expression *Pass1::addRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *retType, std::list< Expression *>::iterator &arg ) {
-			// ***** Code Removal ***** After introducing a temporary variable for all return expressions, the following code appears superfluous.
-			// if ( useRetval ) {
-			// 	assert( retval );
-			// 	arg = appExpr->get_args().insert( arg, new VariableExpr( retval ) );
-			// 	arg++;
-			// } else {
-
 			// Create temporary to hold return value of polymorphic function and produce that temporary as a result
 			// using a comma expression.  Possibly change comma expression into statement expression "{}" for multiple
 			// return values.
+			assert( retType );
 			ObjectDecl *newObj = makeTemporary( retType->clone() );
 			Expression *paramExpr = new VariableExpr( newObj );
@@ -843,6 +837,4 @@
 			appExpr->set_env( 0 );
 			return commaExpr;
-			// } // if
-			// return appExpr;
 		}
 
@@ -878,5 +870,5 @@
 		}
 
-		Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, FunctionType *function, ReferenceToType *dynType, std::list< Expression *>::iterator &arg ) {
+		Expression *Pass1::addDynRetParam( ApplicationExpr *appExpr, FunctionType *function, Type *dynType, std::list< Expression *>::iterator &arg ) {
 			assert( env );
 			Type *concrete = replaceWithConcrete( appExpr, dynType );
@@ -1288,6 +1280,6 @@
 			TyVarMap exprTyVars( (TypeDecl::Kind)-1 );
 			makeTyVarMap( function, exprTyVars );
-			ReferenceToType *concRetType = dynamic_cast< ReferenceToType* >( appExpr->get_result() ); // xxx - is concRetType a good name?
 			ReferenceToType *dynRetType = isDynRet( function, exprTyVars );
+			Type *concRetType = appExpr->get_result();// ?: dynRetType; // xxx - is concRetType a good name?
 
 			if ( dynRetType ) {
@@ -1589,8 +1581,9 @@
 			// move polymorphic return type to parameter list
 			if ( isDynRet( funcType ) ) {
-				DeclarationWithType *ret = funcType->get_returnVals().front();
+				ObjectDecl *ret = safe_dynamic_cast< ObjectDecl* >( funcType->get_returnVals().front() );
 				ret->set_type( new PointerType( Type::Qualifiers(), ret->get_type() ) );
 				funcType->get_parameters().push_front( ret );
 				funcType->get_returnVals().pop_front();
+				ret->set_init( nullptr ); // xxx - memory leak?
 			}
 
Index: src/GenPoly/PolyMutator.cc
===================================================================
--- src/GenPoly/PolyMutator.cc	(revision 33a7b6db7e7a3b3fa85ef51cb227fdc43223b1fd)
+++ src/GenPoly/PolyMutator.cc	(revision d9fa60af0bc172d6842f414cb608e0615d3582a5)
@@ -149,4 +149,20 @@
 	}
 
+	Expression *PolyMutator::mutate( StmtExpr * stmtExpr ) {
+		// don't want statements from outer CompoundStmts to be added to this StmtExpr
+		ValueGuard< std::list< Statement* > > oldStmtsToAdd( stmtsToAdd );
+		ValueGuard< std::list< Statement* > > oldStmtsToAddAfter( stmtsToAddAfter );
+
+		// xxx - not sure if these are needed, along with appropriate assignments, but I don't think so...
+		// ValueGuard< TyVarMap > oldScopeTyVars;
+		// ValueGuard< TypeSubstitution * > oldEnv;
+
+		stmtsToAdd.clear();
+		stmtsToAddAfter.clear();
+
+		stmtExpr->set_result( maybeMutate( stmtExpr->get_result(), *this ) );
+		stmtExpr->set_statements( maybeMutate( stmtExpr->get_statements(), *this ) );
+		return stmtExpr;
+	}
 
 	Initializer *PolyMutator::mutate( SingleInit *singleInit ) {
@@ -154,5 +170,4 @@
 		return singleInit;
 	}
-
 } // namespace GenPoly
 
Index: src/GenPoly/PolyMutator.h
===================================================================
--- src/GenPoly/PolyMutator.h	(revision 33a7b6db7e7a3b3fa85ef51cb227fdc43223b1fd)
+++ src/GenPoly/PolyMutator.h	(revision d9fa60af0bc172d6842f414cb608e0615d3582a5)
@@ -47,4 +47,5 @@
 
 		virtual Expression* mutate(UntypedExpr *untypedExpr);
+		virtual Expression* mutate( StmtExpr *stmtExpr );
 
 		virtual Initializer* mutate(SingleInit *SingleInit);
