Index: src/Virtual/ExpandCasts.cc
===================================================================
--- src/Virtual/ExpandCasts.cc	(revision f19fbbc504e33f9d4eec5177e4abb378bcecf2b7)
+++ src/Virtual/ExpandCasts.cc	(revision 74cfe0546278223b53e1c9e5a60bcecd3ab3ee1a)
@@ -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 ),
