Index: src/Common/ScopedMap.h
===================================================================
--- src/Common/ScopedMap.h	(revision 3ac8b9f795fc403158704c66c51faffe5be12842)
+++ src/Common/ScopedMap.h	(revision 1a39a5a0bcbeb171fe0e5b89de440ca60f18cc21)
@@ -93,5 +93,5 @@
 
 		reference operator* () { return *it; }
-		pointer operator-> () { return it.operator->(); }
+		pointer operator-> () const { return it.operator->(); }
 
 		iterator& operator++ () {
Index: src/Concurrency/Keywords.cc
===================================================================
--- src/Concurrency/Keywords.cc	(revision 3ac8b9f795fc403158704c66c51faffe5be12842)
+++ src/Concurrency/Keywords.cc	(revision 1a39a5a0bcbeb171fe0e5b89de440ca60f18cc21)
@@ -510,5 +510,6 @@
 						new CastExpr(
 							new VariableExpr( func->get_functionType()->get_parameters().front() ),
-							func->get_functionType()->get_parameters().front()->get_type()->stripReferences()->clone()
+							func->get_functionType()->get_parameters().front()->get_type()->stripReferences()->clone(),
+							false
 						)
 					)
@@ -888,5 +889,5 @@
 			new SingleInit( new UntypedExpr(
 				new NameExpr( "get_monitor" ),
-				{  new CastExpr( new VariableExpr( args.front() ), arg_type ) }
+				{  new CastExpr( new VariableExpr( args.front() ), arg_type, false ) }
 			))
 		);
@@ -909,5 +910,5 @@
 					{
 						new SingleInit( new AddressExpr( new VariableExpr( monitors ) ) ),
-						new SingleInit( new CastExpr( new VariableExpr( func ), generic_func->clone() ) )
+						new SingleInit( new CastExpr( new VariableExpr( func ), generic_func->clone(), false ) )
 					},
 					noDesignators,
@@ -946,5 +947,5 @@
 					return new SingleInit( new UntypedExpr(
 						new NameExpr( "get_monitor" ),
-						{  new CastExpr( new VariableExpr( var ), type ) }
+						{  new CastExpr( new VariableExpr( var ), type, false ) }
 					) );
 				})
@@ -970,5 +971,5 @@
 						new SingleInit( new VariableExpr( monitors ) ),
 						new SingleInit( new ConstantExpr( Constant::from_ulong( args.size() ) ) ),
-						new SingleInit( new CastExpr( new VariableExpr( func ), generic_func->clone() ) )
+						new SingleInit( new CastExpr( new VariableExpr( func ), generic_func->clone(), false ) )
 					},
 					noDesignators,
Index: src/Concurrency/Waitfor.cc
===================================================================
--- src/Concurrency/Waitfor.cc	(revision 3ac8b9f795fc403158704c66c51faffe5be12842)
+++ src/Concurrency/Waitfor.cc	(revision 1a39a5a0bcbeb171fe0e5b89de440ca60f18cc21)
@@ -384,5 +384,6 @@
 								decl_monitor
 							)
-						)
+						),
+						false
 					);
 
@@ -408,5 +409,5 @@
 			new CompoundStmt({
 				makeAccStatement( acceptables, index, "is_dtor", detectIsDtor( clause.target.function )                                    , indexer ),
-				makeAccStatement( acceptables, index, "func"   , new CastExpr( clause.target.function, fptr_t )                            , indexer ),
+				makeAccStatement( acceptables, index, "func"   , new CastExpr( clause.target.function, fptr_t, false )                     , indexer ),
 				makeAccStatement( acceptables, index, "data"   , new VariableExpr( monitors )                                              , indexer ),
 				makeAccStatement( acceptables, index, "size"   , new ConstantExpr( Constant::from_ulong( clause.target.arguments.size() ) ), indexer ),
@@ -531,5 +532,6 @@
 								decl_mask
 							)
-						)
+						),
+						false
 					),
 					timeout
Index: src/Parser/ExpressionNode.cc
===================================================================
--- src/Parser/ExpressionNode.cc	(revision 3ac8b9f795fc403158704c66c51faffe5be12842)
+++ src/Parser/ExpressionNode.cc	(revision 1a39a5a0bcbeb171fe0e5b89de440ca60f18cc21)
@@ -427,15 +427,15 @@
 		if ( str[1] == '8' ) goto Default;				// utf-8 characters => array of char
 		// lookup type of associated typedef
-		strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "char16_t", false );
+		strtype = new TypeInstType( Type::Qualifiers( ), "char16_t", false );
 		break;
 	  case 'U':
-		strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "char32_t", false );
+		strtype = new TypeInstType( Type::Qualifiers( ), "char32_t", false );
 		break;
 	  case 'L':
-		strtype = new TypeInstType( Type::Qualifiers( Type::Const ), "wchar_t", false );
+		strtype = new TypeInstType( Type::Qualifiers( ), "wchar_t", false );
 		break;
 	  Default:											// char default string type
 	  default:
-		strtype = new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char );
+		strtype = new BasicType( Type::Qualifiers( ), BasicType::Char );
 	} // switch
 	ArrayType * at = new ArrayType( noQualifiers, strtype,
Index: src/ResolvExpr/AlternativeFinder.cc
===================================================================
--- src/ResolvExpr/AlternativeFinder.cc	(revision 3ac8b9f795fc403158704c66c51faffe5be12842)
+++ src/ResolvExpr/AlternativeFinder.cc	(revision 1a39a5a0bcbeb171fe0e5b89de440ca60f18cc21)
@@ -1216,6 +1216,8 @@
 			unify( castExpr->result, alt.expr->result, alt.env, needAssertions,
 				haveAssertions, openVars, indexer );
-			Cost thisCost = castCost( alt.expr->result, castExpr->result, alt.expr->get_lvalue(),
-				indexer, alt.env );
+			Cost thisCost =
+				castExpr->isGenerated
+				? conversionCost( alt.expr->result, castExpr->result, alt.expr->get_lvalue(),	indexer, alt.env )
+				: castCost( alt.expr->result, castExpr->result, alt.expr->get_lvalue(),	indexer, alt.env );
 			PRINT(
 				std::cerr << "working on cast with result: " << castExpr->result << std::endl;
@@ -1698,9 +1700,23 @@
 
 				// unification run for side-effects
-				unify( toType, alt.expr->result, newEnv, need, have, openVars, indexer );
+				bool canUnify = unify( toType, alt.expr->result, newEnv, need, have, openVars, indexer );
+				(void) canUnify;
 				// xxx - do some inspecting on this line... why isn't result bound to initAlt.type?
 
-				Cost thisCost = castCost( alt.expr->result, toType, alt.expr->get_lvalue(),
+				Cost thisCost = computeConversionCost( alt.expr->result, toType, alt.expr->get_lvalue(),
 					indexer, newEnv );
+
+				PRINT(
+					Cost legacyCost = castCost( alt.expr->result, toType, alt.expr->get_lvalue(),
+						indexer, newEnv );
+					std::cerr << "Considering initialization:";
+					std::cerr << std::endl << "  FROM: "; alt.expr->result->print(std::cerr);
+					std::cerr << std::endl << "  TO: ";   toType          ->print(std::cerr);
+					std::cerr << std::endl << "  Unification " << (canUnify ? "succeeded" : "failed");
+					std::cerr << std::endl << "  Legacy cost " << legacyCost;
+					std::cerr << std::endl << "  New cost " << thisCost;
+					std::cerr << std::endl;
+				)
+				
 				if ( thisCost != Cost::infinity ) {
 					// count one safe conversion for each value that is thrown away
Index: src/ResolvExpr/ConversionCost.cc
===================================================================
--- src/ResolvExpr/ConversionCost.cc	(revision 3ac8b9f795fc403158704c66c51faffe5be12842)
+++ src/ResolvExpr/ConversionCost.cc	(revision 1a39a5a0bcbeb171fe0e5b89de440ca60f18cc21)
@@ -10,6 +10,6 @@
 // Created On       : Sun May 17 07:06:19 2015
 // Last Modified By : Andrew Beach
-// Last Modified On : Mon Aug 12 10:21:00 2019
-// Update Count     : 27
+// Last Modified On : Wed Jul 29 16:11:00 2020
+// Update Count     : 28
 //
 
@@ -392,20 +392,4 @@
 	void ConversionCost::postvisit( const FunctionType * ) {}
 
-	void ConversionCost::postvisit( const StructInstType * inst ) {
-		if ( const StructInstType * destAsInst = dynamic_cast< const StructInstType * >( dest ) ) {
-			if ( inst->name == destAsInst->name ) {
-				cost = Cost::zero;
-			} // if
-		} // if
-	}
-
-	void ConversionCost::postvisit( const UnionInstType * inst ) {
-		if ( const UnionInstType * destAsInst = dynamic_cast< const UnionInstType * >( dest ) ) {
-			if ( inst->name == destAsInst->name ) {
-				cost = Cost::zero;
-			} // if
-		} // if
-	}
-
 	void ConversionCost::postvisit( const EnumInstType * ) {
 		static Type::Qualifiers q;
@@ -681,22 +665,4 @@
 }
 
-void ConversionCost_new::postvisit( const ast::StructInstType * structInstType ) {
-	if ( const ast::StructInstType * dstAsInst =
-			dynamic_cast< const ast::StructInstType * >( dst ) ) {
-		if ( structInstType->name == dstAsInst->name ) {
-			cost = Cost::zero;
-		}
-	}
-}
-
-void ConversionCost_new::postvisit( const ast::UnionInstType * unionInstType ) {
-	if ( const ast::UnionInstType * dstAsInst =
-			dynamic_cast< const ast::UnionInstType * >( dst ) ) {
-		if ( unionInstType->name == dstAsInst->name ) {
-			cost = Cost::zero;
-		}
-	}
-}
-
 void ConversionCost_new::postvisit( const ast::EnumInstType * enumInstType ) {
 	(void)enumInstType;
Index: src/ResolvExpr/ConversionCost.h
===================================================================
--- src/ResolvExpr/ConversionCost.h	(revision 3ac8b9f795fc403158704c66c51faffe5be12842)
+++ src/ResolvExpr/ConversionCost.h	(revision 1a39a5a0bcbeb171fe0e5b89de440ca60f18cc21)
@@ -10,6 +10,6 @@
 // Created On       : Sun May 17 09:37:28 2015
 // Last Modified By : Andrew Beach
-// Last Modified On : Thu Aug  8 16:13:00 2019
-// Update Count     : 6
+// Last Modified On : Wed Jul 29 16:12:00 2020
+// Update Count     : 7
 //
 
@@ -51,6 +51,4 @@
 		void postvisit( const ReferenceType * refType );
 		void postvisit( const FunctionType * functionType );
-		void postvisit( const StructInstType * aggregateUseType );
-		void postvisit( const UnionInstType * aggregateUseType );
 		void postvisit( const EnumInstType * aggregateUseType );
 		void postvisit( const TraitInstType * aggregateUseType );
@@ -102,6 +100,4 @@
 	void postvisit( const ast::ReferenceType * refType );
 	void postvisit( const ast::FunctionType * functionType );
-	void postvisit( const ast::StructInstType * structInstType );
-	void postvisit( const ast::UnionInstType * unionInstType );
 	void postvisit( const ast::EnumInstType * enumInstType );
 	void postvisit( const ast::TraitInstType * traitInstType );
Index: src/SynTree/Expression.h
===================================================================
--- src/SynTree/Expression.h	(revision 3ac8b9f795fc403158704c66c51faffe5be12842)
+++ src/SynTree/Expression.h	(revision 1a39a5a0bcbeb171fe0e5b89de440ca60f18cc21)
@@ -206,5 +206,15 @@
   public:
 	Expression * arg;
-	bool isGenerated = true; // cast generated implicitly by code generation or explicit in program
+
+	// Inidicates cast is introduced by the CFA type system.
+	// true for casts that the resolver introduces to force a return type
+	// false for casts from user code
+	// false for casts from desugaring advanced CFA features into simpler CFA
+	// example
+	//   int * p;     // declaration
+	//   (float *) p; // use, with subject cast
+	// subject cast isGenerated means we are considering an interpretation with a type mismatch
+	// subject cast not isGenerated means someone in charge wants it that way
+	bool isGenerated = true;
 
 	CastExpr( Expression * arg, bool isGenerated = true );
Index: src/Virtual/ExpandCasts.cc
===================================================================
--- src/Virtual/ExpandCasts.cc	(revision 3ac8b9f795fc403158704c66c51faffe5be12842)
+++ src/Virtual/ExpandCasts.cc	(revision 1a39a5a0bcbeb171fe0e5b89de440ca60f18cc21)
@@ -10,6 +10,6 @@
 // Created On       : Mon Jul 24 13:59:00 2017
 // Last Modified By : Andrew Beach
-// Last Modified On : Tue Jul 22 10:04:00 2020
-// Update Count     : 3
+// Last Modified On : Fri Jul 31 10:29:00 2020
+// Update Count     : 4
 //
 
@@ -18,9 +18,8 @@
 #include <cassert>                 // for assert, assertf
 #include <iterator>                // for back_inserter, inserter
-#include <map>                     // for map, _Rb_tree_iterator, map<>::ite...
 #include <string>                  // for string, allocator, operator==, ope...
-#include <utility>                 // for pair
 
 #include "Common/PassVisitor.h"    // for PassVisitor
+#include "Common/ScopedMap.h"      // for ScopedMap
 #include "Common/SemanticError.h"  // for SemanticError
 #include "SymTab/Mangler.h"        // for mangleType
@@ -37,6 +36,13 @@
 	/// Maps virtual table types the instance for that type.
 	class VirtualTableMap final {
-		std::unordered_map<std::string, ObjectDecl *> vtable_instances;
+		ScopedMap<std::string, ObjectDecl *> vtable_instances;
 	public:
+		void enterScope() {
+			vtable_instances.beginScope();
+		}
+		void leaveScope() {
+			vtable_instances.endScope();
+		}
+
 		ObjectDecl * insert( ObjectDecl * vtableDecl ) {
 			std::string const & mangledName = SymTab::Mangler::mangleType( vtableDecl->type );
@@ -93,8 +99,4 @@
 
 	class VirtualCastCore {
-		VirtualTableMap vtable_instances;
-		FunctionDecl *vcast_decl;
-		StructDecl *pvt_decl;
-
 		Type * pointer_to_pvt(int level_of_indirection) {
 			Type * type = new StructInstType(
@@ -108,5 +110,5 @@
 	public:
 		VirtualCastCore() :
-			vtable_instances(), vcast_decl( nullptr ), pvt_decl( nullptr )
+			indexer(), vcast_decl( nullptr ), pvt_decl( nullptr )
 		{}
 
@@ -116,4 +118,9 @@
 
 		Expression * postmutate( VirtualCastExpr * castExpr );
+
+		VirtualTableMap indexer;
+	private:
+		FunctionDecl *vcast_decl;
+		StructDecl *pvt_decl;
 	};
 
@@ -135,5 +142,5 @@
 	void VirtualCastCore::premutate( ObjectDecl * objectDecl ) {
 		if ( is_vtable_inst_name( objectDecl->get_name() ) ) {
-			if ( ObjectDecl * existing = vtable_instances.insert( objectDecl ) ) {
+			if ( ObjectDecl * existing = indexer.insert( objectDecl ) ) {
 				std::string msg = "Repeated instance of virtual table, original found at: ";
 				msg += existing->location.filename;
@@ -222,5 +229,5 @@
 
 		const Type * vtable_type = getVirtualTableType( castExpr );
-		ObjectDecl * table = vtable_instances.lookup( vtable_type );
+		ObjectDecl * table = indexer.lookup( vtable_type );
 		if ( nullptr == table ) {
 			SemanticError( castLocation( castExpr ),
