X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftypes%2FTypes.java;h=f0c9dbddfb2e1383ff746aa9b1a1ce7f1f12e552;hp=a706e2b8f17d3d9415b30c3ccd7eed14ea01b1f9;hb=9a175feb652b2b7bba7afa540831b9076be3c10e;hpb=0b72d3e4ec886838314ffeba0fa201e32c0aae3e diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/Types.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/Types.java index a706e2b8f..f0c9dbddf 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/Types.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/Types.java @@ -147,29 +147,9 @@ public class Types { function = apply(function, parameter); return function; } - - /** - * Get the concrete type or alias type pointed to by a chain of type meta-variables, - * or the last metavariable in the link, if it is not linked to an actual type. - * Unlike {@link #canonical(Type)}, this method does not resolve type aliases. - */ - public static Type weakCanonical(Type type) { - while(true) { - if(type instanceof TMetaVar) { - TMetaVar metaVar = (TMetaVar)type; - if(metaVar.ref == null) - return type; - else - type = metaVar.ref; - } - else - return type; - } - } /** - * Get the concrete type pointed to by a chain of type meta-variables. Unlike {@link #weakCanonical(Type)} - * this method also resolves type aliases. + * Get the concrete type pointed to by a chain of type meta-variables. */ public static Type canonical(Type type) { while(type instanceof TMetaVar) { @@ -795,8 +775,8 @@ public class Types { } public static void unify(Type a, Type b) throws UnificationException { - a = weakCanonical(a); - b = weakCanonical(b); + a = canonical(a); + b = canonical(b); if(a == b) return; if(a instanceof TMetaVar) { @@ -1137,4 +1117,30 @@ public class Types { e.getMessage())); } } + + public static Type instantiateAndStrip(Type type) { + while(true) { + if(type instanceof TForAll) { + TForAll forAll = (TForAll)type; + type = forAll.type.replace(forAll.var, metaVar(forAll.var.getKind())); + } + else if(type instanceof TFun) { + TFun fun = (TFun)type; + if(fun.domain instanceof TPred || fun.domain == Types.PUNIT) + type = fun.range; + else + return type; + } + else if(type instanceof TMetaVar) { + TMetaVar metaVar = (TMetaVar)type; + if(metaVar.ref == null) + return type; + else + type = metaVar.ref; + } + else + return type; + } + } + }