Index: src/InitTweak/FixInit.cc
===================================================================
--- src/InitTweak/FixInit.cc	(revision cf18eeaf30d25339930f9c302988f1cef748926f)
+++ src/InitTweak/FixInit.cc	(revision 668edd6b6837054bf6f09f88e32dc4bcf19590fe)
@@ -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 );
 
