Index: src/ResolvExpr/AlternativeFinder.cc
===================================================================
--- src/ResolvExpr/AlternativeFinder.cc	(revision 403b388ef1aea12eed0de3821475c7367022951e)
+++ src/ResolvExpr/AlternativeFinder.cc	(revision a94b8291fd5d45ed741b2c85713c868ddc3b2bbc)
@@ -779,5 +779,5 @@
 			return ! finalResults.empty();
 		}
-		
+
 		// iterate each current subresult
 		std::size_t genEnd = results.size();
@@ -913,6 +913,6 @@
 
 	template<typename OutputIterator>
-	void AlternativeFinder::makeFunctionAlternatives( const Alternative &func, 
-			FunctionType *funcType, const std::vector< AlternativeFinder > &args, 
+	void AlternativeFinder::makeFunctionAlternatives( const Alternative &func,
+			FunctionType *funcType, const std::vector< AlternativeFinder > &args,
 			OutputIterator out ) {
 		OpenVarSet funcOpenVars;
@@ -920,12 +920,12 @@
 		TypeEnvironment funcEnv( func.env );
 		makeUnifiableVars( funcType, funcOpenVars, funcNeed );
-		// add all type variables as open variables now so that those not used in the parameter 
+		// add all type variables as open variables now so that those not used in the parameter
 		// list are still considered open.
 		funcEnv.add( funcType->get_forall() );
-		
+
 		if ( targetType && ! targetType->isVoid() && ! funcType->get_returnVals().empty() ) {
 			// attempt to narrow based on expected target type
 			Type * returnType = funcType->get_returnVals().front()->get_type();
-			if ( ! unify( returnType, targetType, funcEnv, funcNeed, funcHave, funcOpenVars, 
+			if ( ! unify( returnType, targetType, funcEnv, funcNeed, funcHave, funcOpenVars,
 					indexer ) ) {
 				// unification failed, don't pursue this function alternative
@@ -1035,5 +1035,5 @@
 
 		std::vector< AlternativeFinder > argAlternatives;
-		findSubExprs( untypedExpr->begin_args(), untypedExpr->end_args(), 
+		findSubExprs( untypedExpr->begin_args(), untypedExpr->end_args(),
 			back_inserter( argAlternatives ) );
 
@@ -1065,5 +1065,5 @@
 						Alternative newFunc( *func );
 						referenceToRvalueConversion( newFunc.expr );
-						makeFunctionAlternatives( newFunc, function, argAlternatives, 
+						makeFunctionAlternatives( newFunc, function, argAlternatives,
 							std::back_inserter( candidates ) );
 					}
@@ -1074,9 +1074,9 @@
 							Alternative newFunc( *func );
 							referenceToRvalueConversion( newFunc.expr );
-							makeFunctionAlternatives( newFunc, function, argAlternatives, 
+							makeFunctionAlternatives( newFunc, function, argAlternatives,
 								std::back_inserter( candidates ) );
 						} // if
 					} // if
-				}			
+				}
 			} catch ( SemanticError &e ) {
 				errors.append( e );
@@ -1093,11 +1093,11 @@
 				try {
 					// check if type is a pointer to function
-					if ( PointerType* pointer = dynamic_cast<PointerType*>( 
+					if ( PointerType* pointer = dynamic_cast<PointerType*>(
 							funcOp->expr->get_result()->stripReferences() ) ) {
-						if ( FunctionType* function = 
+						if ( FunctionType* function =
 								dynamic_cast<FunctionType*>( pointer->get_base() ) ) {
 							Alternative newFunc( *funcOp );
 							referenceToRvalueConversion( newFunc.expr );
-							makeFunctionAlternatives( newFunc, function, argAlternatives, 
+							makeFunctionAlternatives( newFunc, function, argAlternatives,
 								std::back_inserter( candidates ) );
 						}
@@ -1138,12 +1138,15 @@
 		candidates.splice( candidates.end(), alternatives );
 
-		findMinCost( candidates.begin(), candidates.end(), std::back_inserter( alternatives ) );
+		// use a new list so that alternatives are not examined by addAnonConversions twice.
+		AltList winners;
+		findMinCost( candidates.begin(), candidates.end(), std::back_inserter( winners ) );
 
 		// function may return struct or union value, in which case we need to add alternatives for implicit
 		// conversions to each of the anonymous members, must happen after findMinCost since anon conversions
 		// are never the cheapest expression
-		for ( const Alternative & alt : alternatives ) {
+		for ( const Alternative & alt : winners ) {
 			addAnonConversions( alt );
 		}
+		alternatives.splice( alternatives.begin(), winners );
 
 		if ( alternatives.empty() && targetType && ! targetType->isVoid() ) {
Index: src/ResolvExpr/RenameVars.cc
===================================================================
--- src/ResolvExpr/RenameVars.cc	(revision 403b388ef1aea12eed0de3821475c7367022951e)
+++ src/ResolvExpr/RenameVars.cc	(revision a94b8291fd5d45ed741b2c85713c868ddc3b2bbc)
@@ -29,5 +29,5 @@
 	RenameVars global_renamer;
 
-	RenameVars::RenameVars() : level( 0 ) {
+	RenameVars::RenameVars() : level( 0 ), resetCount( 0 ) {
 		mapStack.push_front( std::map< std::string, std::string >() );
 	}
@@ -35,4 +35,5 @@
 	void RenameVars::reset() {
 		level = 0;
+		resetCount++;
 	}
 
@@ -130,5 +131,5 @@
 			for ( Type::ForallList::iterator i = type->get_forall().begin(); i != type->get_forall().end(); ++i ) {
 				std::ostringstream output;
-				output << "_" << level << "_" << (*i)->get_name();
+				output << "_" << resetCount << "_" << level << "_" << (*i)->get_name();
 				std::string newname( output.str() );
 				mapStack.front()[ (*i)->get_name() ] = newname;
Index: src/ResolvExpr/RenameVars.h
===================================================================
--- src/ResolvExpr/RenameVars.h	(revision 403b388ef1aea12eed0de3821475c7367022951e)
+++ src/ResolvExpr/RenameVars.h	(revision a94b8291fd5d45ed741b2c85713c868ddc3b2bbc)
@@ -48,5 +48,5 @@
 		void typeBefore( Type *type );
 		void typeAfter( Type *type );
-		int level;
+		int level, resetCount;
 		std::list< std::map< std::string, std::string > > mapStack;
 	};
