update the typeCheck of TypedParameter

This commit is contained in:
ahmad 2024-05-11 13:54:12 +02:00
parent 9f4b158237
commit e49691ff29

View File

@ -6,7 +6,6 @@ import de.maishai.typedast.TypedNode;
import de.maishai.typedast.Type;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import java.util.Map;
@ -24,15 +23,23 @@ public class TypedParameter implements TypedNode {
public void convertToTypedParameter(Map<String, Type> localVar, TypedClass clas, Parameter unTypedParameter) {
paraName = unTypedParameter.name();
type = unTypedParameter.type();
localVar.put(paraName, type);
//localVar.put(paraName, type);
}
@Override
public Type typeCheck(Map<String, Type> localVar, TypedClass clas) {
if (localVar.containsKey(paraName)) {
throw new RuntimeException("Parameter " + paraName + " already exists");
if(clas.isCurrentMethodPresent()){
if(clas.isParameterWitNameInMethod(paraName)) {
throw new RuntimeException("Parameter " + paraName + " already exists");
}
}else if(clas.isCurrentConstructorPresent()){
if(clas.isParameterWitNameInConstructor(paraName)) {
throw new RuntimeException("Parameter " + paraName + " already exists");
}
}
localVar.put(paraName, type);
return type;
}