diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java b/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java index 9e8f964..0634ec5 100644 --- a/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java +++ b/src/main/java/de/maishai/typedast/typedclass/TypedConstructor.java @@ -25,8 +25,12 @@ public class TypedConstructor implements TypedNode { private String name; private List typedParameters = new ArrayList<>(); private TypedBlock typedBlock; - //TODO: add Type - + private Type type; + public TypedConstructor(String name, List typedParameters, TypedBlock typedBlock) { + this.name = name; + this.typedParameters = typedParameters; + this.typedBlock = typedBlock; + } public TypedConstructor(Map localVar, TypedClass clas, Constructor unTypedConstructor) { convertToTypedConstructor(localVar, clas, unTypedConstructor); } @@ -37,6 +41,8 @@ public class TypedConstructor implements TypedNode { for (Parameter param : unTypedConstructor.params()) { typedParameters.add(new TypedParameter(localVar, clas, param)); } + // Konstrukteur hat den Rückgabetyp wie der Klassenname, obwohl es keinen expliziten Rückgabetyp gibt + type = clas.getType(); } public void convertToBlock(Map localVar, TypedClass clas, Constructor unTypedConstructor) { @@ -45,17 +51,7 @@ public class TypedConstructor implements TypedNode { @Override public Type typeCheck(Map localVar, TypedClass clas) { - if (localVar.containsKey(name)) { - throw new RuntimeException("constructor already declared"); - } - localVar.put(name, Type.VOID); - if (typedParameters != null) { - for (TypedParameter param : typedParameters) { - param.typeCheck(localVar, clas); - } - } - typedBlock.typeCheck(localVar, clas); - return Type.VOID; + return type; }