Update isCompatibleElementType for RefType and VectorType.

CL:309203 has a less restrictive assumption for what T
can be in vec<T> and ref<T>. Update the method to disallow
unexpected usage (and to conform the documentation).

Test: hidl_test
Change-Id: I8e4fbb471fd2c206944e3560be5f82239e0b3f84
diff --git a/VectorType.cpp b/VectorType.cpp
index 5854f54..d946bb1 100644
--- a/VectorType.cpp
+++ b/VectorType.cpp
@@ -17,6 +17,7 @@
 #include "VectorType.h"
 
 #include "ArrayType.h"
+#include "CompoundType.h"
 
 #include <hidl-util/Formatter.h>
 #include <android-base/logging.h>
@@ -30,8 +31,38 @@
     return "vector" + (mElementType == nullptr ? "" : (" of " + mElementType->typeName()));
 }
 
-bool VectorType::isCompatibleElementType(Type *) const {
-    return true;
+bool VectorType::isCompatibleElementType(Type *elementType) const {
+    if (elementType->isScalar()) {
+        return true;
+    }
+    if (elementType->isString()) {
+        return true;
+    }
+    if (elementType->isEnum()) {
+        return true;
+    }
+    if (elementType->isBitField()) {
+        return true;
+    }
+    if (elementType->isCompoundType()
+            && static_cast<CompoundType *>(elementType)->style() == CompoundType::STYLE_STRUCT) {
+        return true;
+    }
+    if (elementType->isInterface()) {
+        return true;
+    }
+    if (elementType->isHandle()) {
+        return true;
+    }
+    if (elementType->isTemplatedType()) {
+        Type *inner = static_cast<TemplatedType *>(elementType)->getElementType();
+        return this->isCompatibleElementType(inner) && !inner->isInterface();
+    }
+    if (elementType->isArray()) {
+        Type *inner = static_cast<ArrayType *>(elementType)->getElementType();
+        return this->isCompatibleElementType(inner) && !inner->isInterface();
+    }
+    return false;
 }
 
 void VectorType::addNamedTypesToSet(std::set<const FQName> &set) const {