Index: src/ResolvExpr/CastCost.cc
===================================================================
--- src/ResolvExpr/CastCost.cc	(revision 80e858296a11df7ba60e2471af77bbac5626b427)
+++ src/ResolvExpr/CastCost.cc	(revision 721cd19ff0bf583b48c8ce89d21b2892d6bb485f)
@@ -33,5 +33,5 @@
 	class CastCost : public ConversionCost {
 	  public:
-		CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
+		CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc );
 
 		virtual void visit( BasicType *basicType );
@@ -74,9 +74,9 @@
 		} else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) {
 			PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; )
-			return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const TypeEnvironment & env, const SymTab::Indexer & indexer) {
+			return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const SymTab::Indexer & indexer, const TypeEnvironment & env ) {
 				return ptrsCastable( t1, t2, env, indexer );
 			});
 		} else {
-			CastCost converter( dest, indexer, env );
+			CastCost converter( dest, indexer, env, castCost );
 			src->accept( converter );
 			if ( converter.get_cost() == Cost::infinity ) {
@@ -89,6 +89,6 @@
 	}
 
-	CastCost::CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env )
-		: ConversionCost( dest, indexer, env ) {
+	CastCost::CastCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )
+		: ConversionCost( dest, indexer, env, costFunc ) {
 	}
 
Index: src/ResolvExpr/ConversionCost.cc
===================================================================
--- src/ResolvExpr/ConversionCost.cc	(revision 80e858296a11df7ba60e2471af77bbac5626b427)
+++ src/ResolvExpr/ConversionCost.cc	(revision 721cd19ff0bf583b48c8ce89d21b2892d6bb485f)
@@ -77,9 +77,9 @@
 		} else if ( ReferenceType * refType = dynamic_cast< ReferenceType * > ( dest ) ) {
 			PRINT( std::cerr << "conversionCost: dest is reference" << std::endl; )
-			return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const TypeEnvironment & env, const SymTab::Indexer &){
+			return convertToReferenceCost( src, refType, indexer, env, [](Type * t1, Type * t2, const SymTab::Indexer &, const TypeEnvironment & env ){
 				return ptrsAssignable( t1, t2, env );
 			});
 		} else {
-			ConversionCost converter( dest, indexer, env );
+			ConversionCost converter( dest, indexer, env, conversionCost );
 			src->accept( converter );
 			if ( converter.get_cost() == Cost::infinity ) {
@@ -120,5 +120,5 @@
 					}
 				} else {  // xxx - this discards reference qualifiers from consideration -- reducing qualifiers is a safe conversion; is this right?
-					int assignResult = func( srcAsRef->base, destAsRef->base, env, indexer );
+					int assignResult = func( srcAsRef->base, destAsRef->base, indexer, env );
 					PRINT( std::cerr << "comparing references: " << assignResult << " " << srcAsRef << " " << destAsRef << std::endl; )
 					if ( assignResult > 0 ) {
@@ -130,5 +130,5 @@
 			} else {
 				PRINT( std::cerr << "reference to rvalue conversion" << std::endl; )
-				ConversionCost converter( dest, indexer, env );
+				ConversionCost converter( dest, indexer, env, conversionCost );
 				src->accept( converter );
 				return converter.get_cost();
@@ -173,6 +173,6 @@
 	}
 
-	ConversionCost::ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env )
-		: dest( dest ), indexer( indexer ), cost( Cost::infinity ), env( env ) {
+	ConversionCost::ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction costFunc )
+		: dest( dest ), indexer( indexer ), cost( Cost::infinity ), env( env ), costFunc( costFunc ) {
 	}
 
@@ -320,5 +320,5 @@
 		// recursively compute conversion cost from T1 to T2.
 		// cv can be safely dropped because of 'implicit dereference' behavior.
-		refType->base->accept( *this );
+		cost = costFunc( refType->base, dest, indexer, env );
 		if ( refType->base->get_qualifiers() == dest->get_qualifiers() ) {
 			cost.incReference();  // prefer exact qualifiers
@@ -352,5 +352,5 @@
 		static Type::Qualifiers q;
 		static BasicType integer( q, BasicType::SignedInt );
-		integer.accept( *this );  // safe if dest >= int
+		cost = costFunc( &integer, dest, indexer, env );  // safe if dest >= int
 		if ( cost < Cost::unsafe ) {
 			cost.incSafe();
@@ -364,5 +364,5 @@
 		NamedTypeDecl *namedType;
 		if ( env.lookup( inst->name, eqvClass ) ) {
-			cost = conversionCost( eqvClass.type, dest, indexer, env );
+			cost = costFunc( eqvClass.type, dest, indexer, env );
 		} else if ( TypeInstType *destAsInst = dynamic_cast< TypeInstType* >( dest ) ) {
 			if ( inst->name == destAsInst->name ) {
@@ -374,5 +374,5 @@
 			assert( type );
 			if ( type->base ) {
-				cost = conversionCost( type->base, dest, indexer, env ) + Cost::safe;
+				cost = costFunc( type->base, dest, indexer, env ) + Cost::safe;
 			} // if
 		} // if
@@ -385,5 +385,5 @@
 			std::list< Type * >::const_iterator destIt = destAsTuple->types.begin();
 			while ( srcIt != tupleType->types.end() && destIt != destAsTuple->types.end() ) {
-				Cost newCost = conversionCost( *srcIt++, *destIt++, indexer, env );
+				Cost newCost = costFunc( *srcIt++, *destIt++, indexer, env );
 				if ( newCost == Cost::infinity ) {
 					return;
Index: src/ResolvExpr/ConversionCost.h
===================================================================
--- src/ResolvExpr/ConversionCost.h	(revision 80e858296a11df7ba60e2471af77bbac5626b427)
+++ src/ResolvExpr/ConversionCost.h	(revision 721cd19ff0bf583b48c8ce89d21b2892d6bb485f)
@@ -29,7 +29,8 @@
 	class TypeEnvironment;
 
+	typedef std::function<Cost(Type *, Type *, const SymTab::Indexer &, const TypeEnvironment &)> CostFunction;
 	class ConversionCost : public Visitor {
 	  public:
-		ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
+		ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction );
 
 		Cost get_cost() const { return cost; }
@@ -55,7 +56,8 @@
 		Cost cost;
 		const TypeEnvironment &env;
+		CostFunction costFunc;
 	};
 
-	typedef std::function<int(Type *, Type *, const TypeEnvironment &, const SymTab::Indexer &)> PtrsFunction;
+	typedef std::function<int(Type *, Type *, const SymTab::Indexer &, const TypeEnvironment &)> PtrsFunction;
 	Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func );
 } // namespace ResolvExpr
