Browse Source

Basic array union check

kindlich 5 years ago
parent
commit
d66164d43b
No known key found for this signature in database

+ 22
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMembers.java View File

@@ -39,11 +39,7 @@ import org.openzen.zenscript.codemodel.partial.PartialStaticMemberGroupExpressio
39 39
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
40 40
 import org.openzen.zenscript.codemodel.partial.PartialVariantOptionExpression;
41 41
 import org.openzen.zenscript.codemodel.scope.TypeScope;
42
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
43
-import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
44
-import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
45
-import org.openzen.zenscript.codemodel.type.StoredType;
46
-import org.openzen.zenscript.codemodel.type.TypeID;
42
+import org.openzen.zenscript.codemodel.type.*;
47 43
 
48 44
 import java.util.ArrayList;
49 45
 import java.util.HashMap;
@@ -173,7 +169,27 @@ public final class TypeMembers {
173 169
 			return other;
174 170
 		if (cache.get(other).canCastImplicit(type))
175 171
 			return type;
176
-		
172
+
173
+
174
+		for (TypeMember<ImplementationMemberRef> implementation : this.implementations) {
175
+			final StoredType union = cache.get(implementation.member.implementsType).union(other);
176
+			if(union != null)
177
+				return union;
178
+		}
179
+
180
+		if(this.type.type instanceof ArrayTypeID && other.type instanceof ArrayTypeID) {
181
+			ArrayTypeID thisArray = (ArrayTypeID) this.type.type;
182
+			ArrayTypeID otherArray = (ArrayTypeID) other.type;
183
+
184
+			if(thisArray.dimension == otherArray.dimension) {
185
+				final StoredType union = cache.get(thisArray.elementType).union(otherArray.elementType);
186
+				if(union != null) {
187
+					return getTypeRegistry().getArray(union, thisArray.dimension).stored();
188
+				}
189
+			}
190
+		}
191
+
192
+
177 193
 		return null;
178 194
 	}
179 195
 	

Loading…
Cancel
Save