corrected TypedLocalVariable

This commit is contained in:
ahmad 2024-06-26 22:45:53 +02:00
parent 50b6a821bb
commit a9bebece45

View File

@ -32,12 +32,14 @@ public final class TypedLocalVariable implements TypedNode {
if (typedProgram.getCurrentClass().getCurrentMethod().isLocalVariableInMethod(name)) { if (typedProgram.getCurrentClass().getCurrentMethod().isLocalVariableInMethod(name)) {
throw new RuntimeException("Variable " + name + " already declared"); throw new RuntimeException("Variable " + name + " already declared");
} }
typedProgram.getCurrentClass().getCurrentMethod().getLocalVariables().add(this);
return type; return type;
} }
if (!typedProgram.getCurrentClass().isCurrentMethodPresent() && typedProgram.getCurrentClass().isCurrentConstructorPresent()) { if (!typedProgram.getCurrentClass().isCurrentMethodPresent() && typedProgram.getCurrentClass().isCurrentConstructorPresent()) {
if (typedProgram.getCurrentClass().getCurrentConstructor().isLocalVariableInConstructor(name)) { if (typedProgram.getCurrentClass().getCurrentConstructor().isLocalVariableInConstructor(name)) {
throw new RuntimeException("Variable " + name + " already declared"); throw new RuntimeException("Variable " + name + " already declared");
} }
typedProgram.getCurrentClass().getCurrentConstructor().getLocalVariables().add(this);
return type; return type;
} }
throw new RuntimeException("not found method or constructor in class"); throw new RuntimeException("not found method or constructor in class");