Index: src/GenPoly/GenPoly.cc
===================================================================
--- src/GenPoly/GenPoly.cc	(revision d9f1b2df60273d9c673c37ac6cf70f4752991798)
+++ src/GenPoly/GenPoly.cc	(revision c9d651d543e124ce5ec21ec0f7adf950c5783d6a)
@@ -64,13 +64,20 @@
 			return false;
 		}
+		
+		/// Replaces a TypeInstType by its referrent in the environment, if applicable
+		Type* replaceTypeInst( Type* type, const TypeSubstitution* env ) {
+			if ( ! env ) return type;
+			if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) {
+				Type *newType = env->lookup( typeInst->get_name() );
+				if ( newType ) return newType;
+			}
+			return type;
+		}
 	}
 
 	Type *isPolyType( Type *type, const TypeSubstitution *env ) {
+		type = replaceTypeInst( type, env );
+		
 		if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
-			if ( env ) {
-				if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
-					return isPolyType( newType, env );
-				} // if
-			} // if
 			return type;
 		} else if ( StructInstType *structType = dynamic_cast< StructInstType* >( type ) ) {
@@ -83,10 +90,7 @@
 
 	Type *isPolyType( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
+		type = replaceTypeInst( type, env );
+		
 		if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( type ) ) {
-			if ( env ) {
-				if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
-					return isPolyType( newType, tyVars, env );
-				} // if
-			} // if
 			if ( tyVars.find( typeInst->get_name() ) != tyVars.end() ) {
 				return type;
@@ -101,26 +105,18 @@
 
 	Type *isPolyPtr( Type *type, const TypeSubstitution *env ) {
+		type = replaceTypeInst( type, env );
+		
 		if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
 			return isPolyType( ptr->get_base(), env );
-		} else if ( env ) {
-			if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
-				if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
-					return isPolyPtr( newType, env );
-				} // if
-			} // if
-		} // if
+		}
 		return 0;
 	}
 
 	Type *isPolyPtr( Type *type, const TyVarMap &tyVars, const TypeSubstitution *env ) {
+		type = replaceTypeInst( type, env );
+		
 		if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
 			return isPolyType( ptr->get_base(), tyVars, env );
-		} else if ( env ) {
-			if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
-				if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
-					return isPolyPtr( newType, tyVars, env );
-				} // if
-			} // if
-		} // if
+		}
 		return 0;
 	}
@@ -132,13 +128,9 @@
 
 		while ( true ) {
+			type = replaceTypeInst( type, env );
+		
 			if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
 				type = ptr->get_base();
 				++(*levels);
-			} else if ( env ) {
-				if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
-					if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
-						type = newType;
-					} else break;
-				} else break;
 			} else break;
 		}
@@ -153,13 +145,9 @@
 
 		while ( true ) {
+			type = replaceTypeInst( type, env );
+		
 			if ( PointerType *ptr = dynamic_cast< PointerType *>( type ) ) {
 				type = ptr->get_base();
 				++(*levels);
-			} else if ( env ) {
-				if ( TypeInstType *typeInst = dynamic_cast< TypeInstType *>( type ) ) {
-					if ( Type *newType = env->lookup( typeInst->get_name() ) ) {
-						type = newType;
-					} else break;
-				} else break;
 			} else break;
 		}
Index: src/GenPoly/GenPoly.h
===================================================================
--- src/GenPoly/GenPoly.h	(revision d9f1b2df60273d9c673c37ac6cf70f4752991798)
+++ src/GenPoly/GenPoly.h	(revision c9d651d543e124ce5ec21ec0f7adf950c5783d6a)
@@ -31,5 +31,5 @@
 namespace GenPoly {
 	typedef ErasableScopedMap< std::string, TypeDecl::Kind > TyVarMap;
-
+	
 	/// A function needs an adapter if it returns a polymorphic value or if any of its
 	/// parameters have polymorphic type
