Index: src/SymTab/Validate.cc
===================================================================
--- src/SymTab/Validate.cc	(revision ed8a0d2378d457af8e5826c9d961a9d400fcc6c1)
+++ src/SymTab/Validate.cc	(revision 11ab8ea85897fbd4bb1ca5fccc0c4aeda2c51de6)
@@ -208,4 +208,12 @@
 	};
 
+	/// ensure that generic types have the correct number of type arguments
+	class ValidateGenericParameters : public Visitor {
+	public:
+		typedef Visitor Parent;
+		virtual void visit( StructInstType * inst ) final override;
+		virtual void visit( UnionInstType * inst ) final override;
+	};
+
 	class ArrayLength : public Visitor {
 	public:
@@ -235,9 +243,11 @@
 		Pass3 pass3( 0 );
 		CompoundLiteral compoundliteral;
-
-		HoistStruct::hoistStruct( translationUnit );
+		ValidateGenericParameters genericParams;
+
 		EliminateTypedef::eliminateTypedef( translationUnit );
+		HoistStruct::hoistStruct( translationUnit ); // must happen after EliminateTypedef, so that aggregate typedefs occur in the correct order
 		ReturnTypeFixer::fix( translationUnit ); // must happen before autogen
 		acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions
+		acceptAll( translationUnit, genericParams );  // check as early as possible - can't happen before LinkReferenceToTypes
 		acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist
 		VerifyCtorDtorAssign::verify( translationUnit );  // must happen before autogen, because autogen examines existing ctor/dtors
@@ -829,4 +839,24 @@
 	}
 
+	template< typename Aggr >
+	void validateGeneric( Aggr * inst ) {
+		std::list< TypeDecl * > * params = inst->get_baseParameters();
+		if ( params != NULL ) {
+			std::list< Expression * > & args = inst->get_parameters();
+			if ( args.size() < params->size() ) throw SemanticError( "Too few type arguments in generic type ", inst );
+			if ( args.size() > params->size() ) throw SemanticError( "Too many type arguments in generic type ", inst );
+		}
+	}
+
+	void ValidateGenericParameters::visit( StructInstType * inst ) {
+		validateGeneric( inst );
+		Parent::visit( inst );
+	}
+
+	void ValidateGenericParameters::visit( UnionInstType * inst ) {
+		validateGeneric( inst );
+		Parent::visit( inst );
+	}
+
 	DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {
 		storageClasses = objectDecl->get_storageClasses();
