Index: src/ResolvExpr/Unify.cc
===================================================================
--- src/ResolvExpr/Unify.cc	(revision 70d4b4f92fa857c1dab2358ce4b4861361e4e74c)
+++ src/ResolvExpr/Unify.cc	(revision 02ec39027c7edf89457931dda6e36b7d2d0cee73)
@@ -61,4 +61,5 @@
 
 		template< typename RefType > void handleRefType( RefType *inst, Type *other );
+		template< typename RefType > void handleGenericRefType( RefType *inst, Type *other );
 
 		bool result;
@@ -464,15 +465,49 @@
 
 	template< typename RefType >
-	void Unify::handleRefType( RefType *inst, Type *other ) {  
+	void Unify::handleRefType( RefType *inst, Type *other ) {
+		// check that other type is compatible and named the same
 		RefType *otherStruct = dynamic_cast< RefType* >( other );
 		result = otherStruct && inst->get_name() == otherStruct->get_name();
-	}  
+	}
+
+	template< typename RefType >
+	void Unify::handleGenericRefType( RefType *inst, Type *other ) {
+		// Check that other type is compatible and named the same
+		handleRefType( inst, other );
+		if ( ! result ) return;
+		// Check that parameters of type unify, if any
+		std::list< Expression* > params = inst->get_parameters();
+		if ( ! params.empty() ) {
+			std::list< TypeDecl* > *baseParams = inst->get_baseParameters();
+			if ( ! baseParams ) {
+				result = false;
+				return;
+			}
+			std::list< Expression* >::const_iterator it = params.begin();
+			std::list< TypeDecl* >::const_iterator baseIt = baseParams->begin();
+			while ( it != params.end() && baseIt != baseParams->end()) {
+				TypeExpr *param = dynamic_cast< TypeExpr* >(*it);
+				assert(param && "Aggregate parameters should be type expressions");
+				TypeInstType baseType(Type::Qualifiers(), (*baseIt)->get_name(), *baseIt);
+				if ( ! unifyExact( param->get_type(), &baseType, env, needAssertions, haveAssertions, openVars, WidenMode(false, false), indexer ) ) {
+					result = false;
+					return;
+				}
+				
+				++it;
+				++baseIt;
+			}
+			if ( it != params.end() || baseIt != baseParams->end() ) {
+				result = false;
+			}
+		}
+	}
 
 	void Unify::visit(StructInstType *structInst) {
-		handleRefType( structInst, type2 );
+		handleGenericRefType( structInst, type2 );
 	}
 
 	void Unify::visit(UnionInstType *unionInst) {
-		handleRefType( unionInst, type2 );
+		handleGenericRefType( unionInst, type2 );
 	}
 
