Index: src/InitTweak/FixInit.cc
===================================================================
--- src/InitTweak/FixInit.cc	(revision cf18eeaf30d25339930f9c302988f1cef748926f)
+++ src/InitTweak/FixInit.cc	(revision 5382492c5430535de9cffa7dc941d8aa20acd78d)
@@ -10,5 +10,5 @@
 // Created On       : Wed Jan 13 16:29:30 2016
 // Last Modified By : Rob Schluntz
-// Last Modified On : Mon Apr 25 15:16:12 2016
+// Last Modified On : Tue Apr 26 11:35:31 2016
 // Update Count     : 30
 //
@@ -38,5 +38,5 @@
 	}
 
-	class InsertImplicitCalls : public Mutator {
+	class InsertImplicitCalls : public GenPoly::PolyMutator {
 	public:
 		/// wrap function application expressions as ImplicitCopyCtorExpr nodes
@@ -150,5 +150,15 @@
 
 		// wrap each function call so that it is easy to identify nodes that have to be copy constructed
-		return new ImplicitCopyCtorExpr( appExpr );
+		ImplicitCopyCtorExpr * expr = new ImplicitCopyCtorExpr( appExpr );
+		// save a copy of the type substitution onto the new node so that it is easy to find.
+		// The substitution is needed to obtain the type of temporary variables so that copy constructor
+		// calls can be resolved. Normally this is what PolyMutator is for, but the pass that resolves
+		// copy constructor calls must be an Indexer. We could alternatively make a PolyIndexer which
+		// saves the environment, or compute the types of temporaries here, but it's more simpler to
+		// save the environment here, and more cohesive to compute temporary variables and resolve copy
+		// constructor calls together.
+		assert( env );
+		expr->set_env( env->clone() );
+		return expr;
 	}
 
@@ -185,9 +195,13 @@
 		// take each argument and attempt to copy construct it.
 		for ( Expression * & arg : appExpr->get_args() ) {
+			PRINT( std::cerr << "Type Substitution: " << *impCpCtorExpr->get_env() << std::endl; )
 			// xxx - need to handle tuple arguments
 			assert( ! arg->get_results().empty() );
 			Type * result = arg->get_results().front();
 			if ( skipCopyConstruct( result ) ) continue; // skip certain non-copyable types
-			ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, result->clone(), 0 );
+			// type may involve type variables, so apply type substitution to get temporary variable's actual type
+			result = result->clone();
+			impCpCtorExpr->get_env()->apply( result );
+			ObjectDecl * tmp = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, result, 0 );
 			tmp->get_type()->set_isConst( false );
 
Index: src/SynTree/TypeSubstitution.cc
===================================================================
--- src/SynTree/TypeSubstitution.cc	(revision cf18eeaf30d25339930f9c302988f1cef748926f)
+++ src/SynTree/TypeSubstitution.cc	(revision 5382492c5430535de9cffa7dc941d8aa20acd78d)
@@ -5,10 +5,10 @@
 // file "LICENCE" distributed with Cforall.
 //
-// TypeSubstitution.cc -- 
+// TypeSubstitution.cc --
 //
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Mar  2 17:29:15 2016
+// Last Modified By : Rob Schluntz
+// Last Modified On : Tue Apr 26 11:15:29 2016
 // Update Count     : 3
 //
@@ -96,5 +96,5 @@
 	BoundVarsType::const_iterator bound = boundVars.find( inst->get_name() );
 	if ( bound != boundVars.end() ) return inst;
-	
+
 	TypeEnvType::const_iterator i = typeEnv.find( inst->get_name() );
 	if ( i == typeEnv.end() ) {
@@ -217,4 +217,10 @@
 }
 
+std::ostream & operator<<( std::ostream & out, const TypeSubstitution & sub ) {
+	sub.print( out );
+	return out;
+}
+
+
 // Local Variables: //
 // tab-width: 4 //
Index: src/SynTree/TypeSubstitution.h
===================================================================
--- src/SynTree/TypeSubstitution.h	(revision cf18eeaf30d25339930f9c302988f1cef748926f)
+++ src/SynTree/TypeSubstitution.h	(revision 5382492c5430535de9cffa7dc941d8aa20acd78d)
@@ -5,10 +5,10 @@
 // file "LICENCE" distributed with Cforall.
 //
-// TypeSubstitution.h -- 
+// TypeSubstitution.h --
 //
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Mar  2 17:33:19 2016
+// Last Modified By : Rob Schluntz
+// Last Modified On : Tue Apr 26 11:15:07 2016
 // Update Count     : 2
 //
@@ -33,10 +33,10 @@
 	TypeSubstitution( const TypeSubstitution &other );
 	virtual ~TypeSubstitution();
-	
+
 	TypeSubstitution &operator=( const TypeSubstitution &other );
-	
+
 	template< typename SynTreeClass > int apply( SynTreeClass *&input );
 	template< typename SynTreeClass > int applyFree( SynTreeClass *&input );
-	
+
 	void add( std::string formalType, Type *actualType );
 	void add( const TypeSubstitution &other );
@@ -44,11 +44,11 @@
 	Type *lookup( std::string formalType ) const;
 	bool empty() const;
-	
+
 	template< typename FormalIterator, typename ActualIterator >
 	void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin );
-	
+
 	template< typename TypeInstListIterator >
 	void extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result );
-	
+
 	void normalize();
 
@@ -63,5 +63,5 @@
 	/// Records type variable bindings from forall-statements and instantiations of generic types
 	template< typename TypeClass > Type *handleAggregateType( TypeClass *type );
-	
+
 	virtual Type* mutate(VoidType *basicType);
 	virtual Type* mutate(BasicType *basicType);
@@ -75,7 +75,7 @@
 	virtual Type* mutate(TupleType *tupleType);
 	virtual Type* mutate(VarArgsType *varArgsType);
-	
+
 	// TODO: worry about traversing into a forall-qualified function type or type decl with assertions
-	
+
 	void initialize( const TypeSubstitution &src, TypeSubstitution &dest );
 
@@ -136,5 +136,5 @@
 	return subCount;
 }
-	
+
 template< typename SynTreeClass >
 int TypeSubstitution::applyFree( SynTreeClass *&input ) {
@@ -149,5 +149,5 @@
 	return subCount;
 }
-	
+
 template< typename TypeInstListIterator >
 void TypeSubstitution::extract( TypeInstListIterator begin, TypeInstListIterator end, TypeSubstitution &result ) {
@@ -173,4 +173,6 @@
 }
 
+std::ostream & operator<<( std::ostream & out, const TypeSubstitution & sub );
+
 #endif // TYPESUBSTITUTION_H
 
