]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/kinds/Kinds.java
migrated to svn revision 33108
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / types / kinds / Kinds.java
index edf63df740a4d871910eddde4be0708341f09ab9..4707110f8d9f374af01c761fb1200038d7a5f1ce 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.scl.compiler.types.kinds;
 
+import org.simantics.scl.compiler.common.exceptions.InternalCompilerError;
 import org.simantics.scl.compiler.types.exceptions.KindUnificationException;
 
 public class Kinds {
@@ -77,5 +78,24 @@ public class Kinds {
 
     public static boolean equals(Kind a, Kind b) {
         return equalsCanonical(canonical(a), canonical(b));
+    }
+
+    public static Kind rangeOfArrow(Kind kind) {
+        kind = canonical(kind);
+        if(kind instanceof KArrow)
+            return ((KArrow)kind).range;
+        else if(kind instanceof KMetaVar) {
+            Kind domain = Kinds.metaVar();
+            Kind range = Kinds.metaVar();
+            try {
+                ((KMetaVar)kind).setRef(arrow(domain, range));
+            } catch (KindUnificationException e) {
+                // Should not fail because kind is canonical
+                e.printStackTrace();
+            }
+            return range;
+        }
+        else
+            throw new InternalCompilerError("Assumed arrow kind but encountered " + kind + ".");
     }    
 }