diff --git a/src/main/java/edu/kit/typicalc/model/Tree.java b/src/main/java/edu/kit/typicalc/model/Tree.java index 650f343..f70bec8 100644 --- a/src/main/java/edu/kit/typicalc/model/Tree.java +++ b/src/main/java/edu/kit/typicalc/model/Tree.java @@ -41,7 +41,7 @@ public class Tree implements TermVisitorTree { * @param lambdaTerm the lambda term to generate the tree for */ protected Tree(Map typeAssumptions, LambdaTerm lambdaTerm) { - this(typeAssumptions, lambdaTerm, new TypeVariableFactory(TypeVariableKind.TREE)); + this(typeAssumptions, lambdaTerm, new TypeVariableFactory(TypeVariableKind.TREE), false); } /** @@ -54,13 +54,14 @@ public class Tree implements TermVisitorTree { * @param typeAssumptions the type assumptions to consider when generating the tree * @param lambdaTerm the lambda term to generate the tree for * @param typeVariableFactory the type variable factory to use + * @param partOfLetTerm indicates whether the tree is generated for a sub-inference that is part of a let term */ protected Tree(Map typeAssumptions, LambdaTerm lambdaTerm, - TypeVariableFactory typeVariableFactory) { + TypeVariableFactory typeVariableFactory, boolean partOfLetTerm) { this.typeVarFactory = typeVariableFactory; this.constraints = new ArrayList<>(); - this.stepFactory = lambdaTerm.hasLet() ? new StepFactoryWithLet() : new StepFactoryDefault(); + this.stepFactory = lambdaTerm.hasLet() || partOfLetTerm ? new StepFactoryWithLet() : new StepFactoryDefault(); this.firstTypeVariable = typeVarFactory.nextTypeVariable(); this.firstInferenceStep = lambdaTerm.accept(this, typeAssumptions, firstTypeVariable); diff --git a/src/main/java/edu/kit/typicalc/model/TypeInfererLet.java b/src/main/java/edu/kit/typicalc/model/TypeInfererLet.java index 53a7620..840a70e 100644 --- a/src/main/java/edu/kit/typicalc/model/TypeInfererLet.java +++ b/src/main/java/edu/kit/typicalc/model/TypeInfererLet.java @@ -27,12 +27,12 @@ public class TypeInfererLet implements TypeInfererInterface { * * @param lambdaTerm the lambda term to generate the tree for * @param typeAssumptions the type assumptions to consider when generating the tree - * @param typeVarFactory the type variable factory that should be used in this inference to guarantee consistecy + * @param typeVarFactory the type variable factory that should be used in this inference to guarantee consistency * with the outer inference */ protected TypeInfererLet(LambdaTerm lambdaTerm, Map typeAssumptions, TypeVariableFactory typeVarFactory) { - tree = new Tree(typeAssumptions, lambdaTerm, typeVarFactory); + tree = new Tree(typeAssumptions, lambdaTerm, typeVarFactory, true); // cancel algorithm if a sub-inference failed if (tree.hasFailedSubInference()) { diff --git a/src/test/java/edu/kit/typicalc/model/TreeTest.java b/src/test/java/edu/kit/typicalc/model/TreeTest.java index 4aa6d62..a6d2209 100644 --- a/src/test/java/edu/kit/typicalc/model/TreeTest.java +++ b/src/test/java/edu/kit/typicalc/model/TreeTest.java @@ -40,7 +40,7 @@ class TreeTest { factory.nextTypeVariable(); factoryRef.nextTypeVariable(); } - Tree tree = new Tree(TYPE_ASSUMPTIONS, VAR, factory); + Tree tree = new Tree(TYPE_ASSUMPTIONS, VAR, factory, false); assertEquals(tree.getFirstTypeVariable(), factoryRef.nextTypeVariable()); }