Actually fix exception thrown by last example

This commit is contained in:
Moritz Dieing 2021-09-29 17:11:37 +02:00
parent 49adac2a88
commit 8db0436975
2 changed files with 12 additions and 19 deletions

View File

@ -193,12 +193,15 @@ public class ExplanationCreator implements StepVisitor {
explanationTexts.add(createLatexLetStep(letD, variable, innerTerm, variableDefinition)); explanationTexts.add(createLatexLetStep(letD, variable, innerTerm, variableDefinition));
letD.getTypeInferer().getFirstInferenceStep().accept(this); letD.getTypeInferer().getFirstInferenceStep().accept(this);
// skip creation of unification texts if nested let produced an error
if (!errorOccurred) {
ExplanationCreatorUnification unification = ExplanationCreatorUnification unification =
new ExplanationCreatorUnification(letD.getTypeInferer(), locale, provider, MODE, letCounter, true, new ExplanationCreatorUnification(letD.getTypeInferer(), locale, provider, MODE, letCounter, true,
Optional.of(variable)); Optional.of(variable));
explanationTexts.addAll(unification.getUnificationsTexts().getLeft()); explanationTexts.addAll(unification.getUnificationsTexts().getLeft());
errorOccurred = unification.getUnificationsTexts().getRight(); errorOccurred = unification.getUnificationsTexts().getRight();
letCounter--; letCounter--;
}
if (!errorOccurred) { if (!errorOccurred) {
letD.getPremise().accept(this); letD.getPremise().accept(this);

View File

@ -105,8 +105,6 @@ public class ExplanationCreatorUnification {
if (isLetUnification) { if (isLetUnification) {
createLetUnficiationFinish(); createLetUnficiationFinish();
} }
} else if (isLetUnification) {
unificationTexts.remove(unificationTexts.size() - 1);
} }
} }
@ -159,7 +157,6 @@ public class ExplanationCreatorUnification {
return provider.getTranslation(textKey, locale); return provider.getTranslation(textKey, locale);
} }
// WARNING: call toLatex() before to get proper latex code
private String letCounterToLatex(String setName) { private String letCounterToLatex(String setName) {
switch (letCounter) { switch (letCounter) {
case 0: case 0:
@ -187,13 +184,8 @@ public class ExplanationCreatorUnification {
} }
private void createUnficationTexts() { private void createUnficationTexts() {
List<UnificationStep> unificationSteps; List<UnificationStep> unificationSteps = typeInferer.getUnificationSteps()
if (typeInferer.getUnificationSteps().isPresent()) { .orElseThrow(IllegalStateException::new);
unificationSteps = typeInferer.getUnificationSteps().get();
} else {
errorOccurred = true;
return;
}
// skip first step since the substitutions list is still empty (unification introduction is shown) // skip first step since the substitutions list is still empty (unification introduction is shown)
for (int stepNum = 1; stepNum < unificationSteps.size(); stepNum++) { for (int stepNum = 1; stepNum < unificationSteps.size(); stepNum++) {
@ -258,10 +250,8 @@ public class ExplanationCreatorUnification {
private void createErrorText(UnificationError errorType) { private void createErrorText(UnificationError errorType) {
if (errorType == UnificationError.INFINITE_TYPE) { if (errorType == UnificationError.INFINITE_TYPE) {
unificationTexts.add(getDefaultTextLatex(KEY_PREFIX + "infiniteType")); unificationTexts.add(getDefaultTextLatex(KEY_PREFIX + "infiniteType"));
unificationTexts.add(getDefaultTextLatex(KEY_PREFIX + "infiniteType"));
} else if (errorType == UnificationError.DIFFERENT_TYPES) { } else if (errorType == UnificationError.DIFFERENT_TYPES) {
unificationTexts.add(getDefaultTextLatex(KEY_PREFIX + "differentTypes")); unificationTexts.add(getDefaultTextLatex(KEY_PREFIX + "differentTypes"));
unificationTexts.add(getDefaultTextLatex(KEY_PREFIX + "differentTypes"));
} }
} }