Index: src/Parser/DeclarationNode.cc
===================================================================
--- src/Parser/DeclarationNode.cc	(revision ca1a5475f4eddc0c66780db2fd4589594588899b)
+++ src/Parser/DeclarationNode.cc	(revision 43c89a78fd93abc599e03ce30605af5a82c4e1cc)
@@ -10,6 +10,6 @@
 // Created On       : Sat May 16 12:34:05 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Feb 23 15:45:02 2017
-// Update Count     : 759
+// Last Modified On : Thu Feb 23 22:21:06 2017
+// Update Count     : 775
 //
 
@@ -607,5 +607,8 @@
 					type->aggInst.aggregate = o->type;
 					if ( o->type->kind == TypeData::Aggregate ) {
+						type->aggInst.hoistType = o->type->aggregate.body;
 						type->aggInst.params = maybeClone( o->type->aggregate.actuals );
+					} else {
+						type->aggInst.hoistType = o->type->enumeration.body;
 					} // if
 					type->qualifiers |= o->type->qualifiers;
@@ -881,4 +884,6 @@
 				newType->aggInst.aggregate->aggregate.fields = nullptr;
 			} // if
+			// don't hoist twice
+			newType->aggInst.hoistType = false;
 		} // if
 
@@ -941,5 +946,5 @@
 	SemanticError errors;
 	std::back_insert_iterator< std::list< DeclarationWithType * > > out( outputList );
-	
+
 	for ( const DeclarationNode * cur = firstNode; cur; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ) ) {
 		try {
@@ -953,5 +958,5 @@
 					auto obj = new ObjectDecl( "", DeclarationNode::NoStorageClass, linkage, nullptr, inst, nullptr );
 					obj->location = cur->location;
-					* out++ = obj; 
+					* out++ = obj;
 					delete agg;
 				} else if ( UnionDecl * agg = dynamic_cast< UnionDecl * >( decl ) ) {
@@ -1035,46 +1040,7 @@
 
 	switch ( type->kind ) {
-	  case TypeData::Enum: {
-		  if ( type->enumeration.body ) {
-			  EnumDecl * typedecl = buildEnum( type, attributes );
-			  return new EnumInstType( buildQualifiers( type ), typedecl );
-		  } else {
-			  return new EnumInstType( buildQualifiers( type ), *type->enumeration.name );
-		  }
-	  }
+	  case TypeData::Enum:
 	  case TypeData::Aggregate: {
-		  ReferenceToType * ret;
-		  if ( type->aggregate.body ) {
-			  AggregateDecl * typedecl = buildAggregate( type, attributes );
-			  switch ( type->aggregate.kind ) {
-				case DeclarationNode::Struct:
-				  ret = new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl );
-				  break;
-				case DeclarationNode::Union:
-				  ret = new UnionInstType( buildQualifiers( type ), (UnionDecl *)typedecl );
-				  break;
-				case DeclarationNode::Trait:
-				  assert( false );
-				  //ret = new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl );
-				  break;
-				default:
-				  assert( false );
-			  } // switch
-		  } else {
-			  switch ( type->aggregate.kind ) {
-				case DeclarationNode::Struct:
-				  ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
-				  break;
-				case DeclarationNode::Union:
-				  ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
-				  break;
-				case DeclarationNode::Trait:
-				  assert( false );
-				  //ret = new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl );
-				  break;
-				default:
-				  assert( false );
-			  } // switch
-		  } // if
+		  ReferenceToType * ret = buildComAggInst( type, attributes );
 		  buildList( type->aggregate.actuals, ret->get_parameters() );
 		  return ret;
Index: src/Parser/TypeData.cc
===================================================================
--- src/Parser/TypeData.cc	(revision ca1a5475f4eddc0c66780db2fd4589594588899b)
+++ src/Parser/TypeData.cc	(revision 43c89a78fd93abc599e03ce30605af5a82c4e1cc)
@@ -10,6 +10,6 @@
 // Created On       : Sat May 16 15:12:51 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Feb 23 16:26:39 2017
-// Update Count     : 477
+// Last Modified On : Thu Feb 23 21:48:55 2017
+// Update Count     : 485
 //
 
@@ -62,4 +62,5 @@
 		aggInst.aggregate = nullptr;
 		aggInst.params = nullptr;
+		aggInst.hoistType = false;;
 		break;
 	  case Enum:
@@ -195,4 +196,5 @@
 		newtype->aggInst.aggregate = maybeClone( aggInst.aggregate );
 		newtype->aggInst.params = maybeClone( aggInst.params );
+		newtype->aggInst.hoistType = aggInst.hoistType;
 		break;
 	  case Enum:
@@ -644,27 +646,85 @@
 } // buildAggregate
 
+ReferenceToType * buildComAggInst( const TypeData * type, std::list< Attribute * > attributes ) {
+	switch ( type->kind ) {
+	  case TypeData::Enum: {
+		  if ( type->enumeration.body ) {
+			  EnumDecl * typedecl = buildEnum( type, attributes );
+			  return new EnumInstType( buildQualifiers( type ), typedecl );
+		  } else {
+			  return new EnumInstType( buildQualifiers( type ), *type->enumeration.name );
+		  } // if
+	  }
+	  case TypeData::Aggregate: {
+		  ReferenceToType * ret;
+		  if ( type->aggregate.body ) {
+			  AggregateDecl * typedecl = buildAggregate( type, attributes );
+			  switch ( type->aggregate.kind ) {
+				case DeclarationNode::Struct:
+				  ret = new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl );
+				  break;
+				case DeclarationNode::Union:
+				  ret = new UnionInstType( buildQualifiers( type ), (UnionDecl *)typedecl );
+				  break;
+				case DeclarationNode::Trait:
+				  assert( false );
+				  //ret = new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl );
+				  break;
+				default:
+				  assert( false );
+			  } // switch
+		  } else {
+			  switch ( type->aggregate.kind ) {
+				case DeclarationNode::Struct:
+				  ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
+				  break;
+				case DeclarationNode::Union:
+				  ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
+				  break;
+				case DeclarationNode::Trait:
+				  ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name );
+				  break;
+				default:
+				  assert( false );
+			  } // switch
+		  } // if
+		  return ret;
+	  }
+	  default:
+		assert( false );
+	} // switch
+} // buildAggInst
+
 ReferenceToType * buildAggInst( const TypeData * td ) {
 	assert( td->kind == TypeData::AggregateInst );
 
-	ReferenceToType * ret;
-	if ( td->aggInst.aggregate->kind == TypeData::Enum ) {
-		ret = new EnumInstType( buildQualifiers( td ), *td->aggInst.aggregate->enumeration.name );
-	} else {
-		assert( td->aggInst.aggregate->kind == TypeData::Aggregate );
-		switch ( td->aggInst.aggregate->aggregate.kind ) {
-		  case DeclarationNode::Struct:
-			assert( td->aggInst.aggregate->aggregate.name );
-			ret = new StructInstType( buildQualifiers( td ), *td->aggInst.aggregate->aggregate.name );
-			break;
-		  case DeclarationNode::Union:
-			ret = new UnionInstType( buildQualifiers( td ), *td->aggInst.aggregate->aggregate.name );
-			break;
-		  case DeclarationNode::Trait:
-			ret = new TraitInstType( buildQualifiers( td ), *td->aggInst.aggregate->aggregate.name );
-			break;
-		  default:
-			assert( false );
-		} // switch
-	} // if
+	// ReferenceToType * ret = buildComAggInst( td->aggInst.aggregate, std::list< Attribute * >() );
+	ReferenceToType * ret = nullptr;
+	TypeData * type = td->aggInst.aggregate;
+	switch ( type->kind ) {
+	  case TypeData::Enum: {
+		  return new EnumInstType( buildQualifiers( type ), *type->enumeration.name );
+	  }
+	  case TypeData::Aggregate: {
+		  switch ( type->aggregate.kind ) {
+			case DeclarationNode::Struct:
+			  ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
+			  break;
+			case DeclarationNode::Union:
+			  ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
+			  break;
+			case DeclarationNode::Trait:
+			  ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name );
+			  break;
+			default:
+			  assert( false );
+		  } // switch
+	  }
+	  break;
+	  default:
+		assert( false );
+	} // switch
+
+	ret->set_hoistType( td->aggInst.hoistType );
 	buildList( td->aggInst.params, ret->get_parameters() );
 	buildForall( td->forall, ret->get_forall() );
Index: src/Parser/TypeData.h
===================================================================
--- src/Parser/TypeData.h	(revision ca1a5475f4eddc0c66780db2fd4589594588899b)
+++ src/Parser/TypeData.h	(revision 43c89a78fd93abc599e03ce30605af5a82c4e1cc)
@@ -10,6 +10,6 @@
 // Created On       : Sat May 16 15:18:36 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Feb 23 15:16:18 2017
-// Update Count     : 155
+// Last Modified On : Thu Feb 23 17:14:46 2017
+// Update Count     : 158
 //
 
@@ -38,4 +38,5 @@
 		TypeData * aggregate;
 		ExpressionNode * params;
+		bool hoistType;
 	};
 
@@ -104,4 +105,5 @@
 ArrayType * buildArray( const TypeData * );
 AggregateDecl * buildAggregate( const TypeData *, std::list< Attribute * > );
+ReferenceToType * buildComAggInst( const TypeData *, std::list< Attribute * > attributes );
 ReferenceToType * buildAggInst( const TypeData * );
 NamedTypeDecl * buildSymbolic( const TypeData *, const std::string &name, DeclarationNode::StorageClass sc );
