Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision b7260842d3d46862cb3406f96e73c6e605589177)
+++ src/GenPoly/Box.cc	(revision 33a7b6db7e7a3b3fa85ef51cb227fdc43223b1fd)
@@ -1288,8 +1288,9 @@
 			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 );
 
 			if ( dynRetType ) {
-				ret = addDynRetParam( appExpr, function, dynRetType, arg );
+				ret = addDynRetParam( appExpr, function, concRetType, arg ); // xxx - used to use dynRetType instead of concRetType
 			} else if ( needsAdapter( function, scopeTyVars ) ) {
 				// std::cerr << "needs adapter: ";
@@ -1301,5 +1302,5 @@
 			arg = appExpr->get_args().begin();
 
-			passTypeVars( appExpr, dynRetType, arg, exprTyVars );
+			passTypeVars( appExpr, concRetType, arg, exprTyVars ); // xxx - used to use dynRetType instead of concRetType
 			addInferredParams( appExpr, function, arg, exprTyVars );
 
@@ -1364,4 +1365,5 @@
 			// line below cloned from FixFunction.cc
 			// xxx - functionObj is never added to a list of declarations...
+			// alternatively, this function could return a new VariableExpr( functionDecl ) and change the result type of the new expression
 			ObjectDecl *functionObj = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClass(), functionDecl->get_linkage(), 0,
 			                                          new PointerType( Type::Qualifiers(), functionDecl->get_type()->clone() ), 0 );
Index: src/GenPoly/GenPoly.cc
===================================================================
--- src/GenPoly/GenPoly.cc	(revision b7260842d3d46862cb3406f96e73c6e605589177)
+++ src/GenPoly/GenPoly.cc	(revision 33a7b6db7e7a3b3fa85ef51cb227fdc43223b1fd)
@@ -92,5 +92,5 @@
 	}
 
-	Type *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
+	ReferenceToType *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
 		type = replaceTypeInst( type, env );
 
@@ -98,10 +98,10 @@
 			auto var = tyVars.find( typeInst->get_name() );
 			if ( var != tyVars.end() && var->second == TypeDecl::Any ) {
-				return type;
+				return typeInst;
 			}
 		} else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) {
-			if ( hasDynParams( structType->get_parameters(), tyVars, env ) ) return type;
+			if ( hasDynParams( structType->get_parameters(), tyVars, env ) ) return structType;
 		} else if ( UnionInstType *unionType = dynamic_cast< UnionInstType* >( type ) ) {
-			if ( hasDynParams( unionType->get_parameters(), tyVars, env ) ) return type;
+			if ( hasDynParams( unionType->get_parameters(), tyVars, env ) ) return unionType;
 		}
 		return 0;
Index: src/GenPoly/GenPoly.h
===================================================================
--- src/GenPoly/GenPoly.h	(revision b7260842d3d46862cb3406f96e73c6e605589177)
+++ src/GenPoly/GenPoly.h	(revision 33a7b6db7e7a3b3fa85ef51cb227fdc43223b1fd)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// GenPoly.h -- 
+// GenPoly.h --
 //
 // Author           : Richard C. Bilson
@@ -34,13 +34,13 @@
 	/// Replaces a TypeInstType by its referrent in the environment, if applicable
 	Type* replaceTypeInst( Type* type, const TypeSubstitution* env );
-	
+
 	/// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
 	Type *isPolyType( Type *type, const TypeSubstitution *env = 0 );
-	
+
 	/// returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
 	Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
 
 	/// returns dynamic-layout type if is dynamic-layout type in tyVars, NULL otherwise; will look up substitution in env if provided
-	Type *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
+	ReferenceToType *isDynType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
 
 	/// true iff function has dynamic-layout return type under the given type variable map
@@ -55,5 +55,5 @@
 	/// returns polymorphic type if is pointer to polymorphic type, NULL otherwise; will look up substitution in env if provided
 	Type *isPolyPtr( Type *type, const TypeSubstitution *env = 0 );
-	
+
 	/// returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided
 	Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env = 0 );
@@ -76,5 +76,5 @@
 	/// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `tyVarMap`
 	void makeTyVarMap( Type *type, TyVarMap &tyVarMap );
-	
+
 	/// Prints type variable map
 	void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
@@ -82,5 +82,5 @@
 	/// Gets the mangled name of this type; alias for SymTab::Mangler::mangleType().
 	inline std::string mangleType( Type *ty ) { return SymTab::Mangler::mangleType( ty ); }
-	
+
 	/// Gets the name of the sizeof parameter for the type, given its mangled name
 	inline std::string sizeofName( const std::string &name ) { return std::string( "_sizeof_" ) + name; }
@@ -94,5 +94,5 @@
 	/// Gets the name of the layout function for a given aggregate type, given its declaration
 	inline std::string layoutofName( AggregateDecl *decl ) { return std::string( "_layoutof_" ) + decl->get_name(); }
-	
+
 } // namespace GenPoly
 
