forked from JavaTX/JavaCompilerCore
unifier fixed (no iterated application necessary anymore)
This commit is contained in:
parent
6778160315
commit
863904a4e8
@ -41,16 +41,13 @@ public final class TypeParams implements Iterable<Type>{
|
||||
}
|
||||
|
||||
public boolean occurs(PlaceholderType t) {
|
||||
for(Type p : typeParams) {
|
||||
if(p instanceof PlaceholderType) {
|
||||
for(Type p : typeParams)
|
||||
if(p instanceof PlaceholderType)
|
||||
if(p.equals(t))
|
||||
return true;
|
||||
} else {
|
||||
else
|
||||
if(p.getTypeParams().occurs(t))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,9 @@ public class Unifier implements Function<Type, Type> {
|
||||
}
|
||||
|
||||
public void Add(PlaceholderType source, Type target) {
|
||||
Unifier tempU = new Unifier(source, target);
|
||||
for(PlaceholderType pt : substitutions.keySet())
|
||||
substitutions.put(pt, substitutions.get(pt).apply(tempU));
|
||||
substitutions.put(source, target);
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,9 @@ public class MartelliMontanariUnify implements IUnify {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!check(pair)) // Occurs-Check
|
||||
// Occurs-Check
|
||||
if(pair.getLhsType() instanceof PlaceholderType
|
||||
&& pair.getRhsType().getTypeParams().occurs((PlaceholderType) pair.getLhsType()))
|
||||
return Optional.empty();
|
||||
|
||||
Optional<Entry<PlaceholderType, Type>> optUni = eliminate(pair);
|
||||
@ -120,20 +122,7 @@ public class MartelliMontanariUnify implements IUnify {
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private boolean check(MPair pair) {
|
||||
Type rhs = pair.getRhsType();
|
||||
Type lhs = pair.getLhsType();
|
||||
|
||||
TypeParams rhsTypeParams = rhs.getTypeParams();
|
||||
|
||||
for(Type t : rhsTypeParams)
|
||||
if(lhs.equals(t))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private Optional<Entry<PlaceholderType, Type>> eliminate(MPair pair) {
|
||||
Type rhs = pair.getRhsType();
|
||||
Type lhs = pair.getLhsType();
|
||||
|
Loading…
Reference in New Issue
Block a user