]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/types/JavaTypeTranslator.java
Merged changes from feature/scl to master.
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / codegen / types / JavaTypeTranslator.java
index 2e2dcef2f5778685e9022f6020a610fb64fea8b5..c528d83a65436addac291ab7f40ce54a3e1aadf0 100644 (file)
@@ -2,7 +2,9 @@ package org.simantics.scl.compiler.internal.codegen.types;
 
 import org.cojen.classfile.TypeDesc;
 import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
+import org.simantics.scl.compiler.elaboration.modules.TypeAlias;
 import org.simantics.scl.compiler.elaboration.modules.TypeConstructor;
+import org.simantics.scl.compiler.elaboration.modules.TypeDescriptor;
 import org.simantics.scl.compiler.environment.Environment;
 import org.simantics.scl.compiler.internal.codegen.utils.Constants;
 import org.simantics.scl.compiler.types.TApply;
@@ -33,16 +35,20 @@ public class JavaTypeTranslator {
             parameters[len-i-1] = temp;
         }
     }
+    
+    private TypeConstructor getTypeConstructor(TCon con) {
+        TypeDescriptor typeDescriptor = environment.getTypeDescriptor(con);
+        if(typeDescriptor == null)
+            throw new InternalCompilerError("Didn't find type constructor " + con.module + "/" + con.name + ".");
+        if(typeDescriptor instanceof TypeAlias)
+            throw new InternalCompilerError("Type " + con.module + "/" + con.name + " is a type alias.");
+        return (TypeConstructor)typeDescriptor;
+    }
         
     public TypeDesc toTypeDesc(Type type) {
         while(true) {
-            if(type instanceof TCon) {
-                TCon con = (TCon)type;
-                TypeConstructor typeConstructor = environment.getTypeConstructor(con);
-                if(typeConstructor == null)
-                    throw new InternalCompilerError("Didn't find type constructor " + con.module + "/" + con.name + ".");
-                return typeConstructor.construct(this, Type.EMPTY_ARRAY);
-            }
+            if(type instanceof TCon)
+                return getTypeConstructor((TCon)type).construct(this, Type.EMPTY_ARRAY);
             else if(type instanceof TApply) {
                 int i=0;
                 while(true) {
@@ -51,7 +57,7 @@ public class JavaTypeTranslator {
                     type = Types.canonical(apply.function);
                     if(type instanceof TCon) {
                         reverseParameters(i);
-                        return environment.getTypeConstructor((TCon)type).construct(this, parameters);
+                        return getTypeConstructor((TCon)type).construct(this, parameters);
                     }
                     else if(type instanceof TApply)
                         ;