mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 01:28:03 +00:00
Fixed error of constructor which is not named like class name
This commit is contained in:
parent
de9365d5c9
commit
ad770213d3
@ -56,7 +56,7 @@ public class TypedClass implements TypedNode {
|
||||
typedDeclarations.add(new TypedDeclaration(typedProgram, declaration));
|
||||
}
|
||||
for (Constructor constructor : c.constructors()) {
|
||||
typedConstructors.add(new TypedConstructor(typedProgram, constructor));
|
||||
typedConstructors.add(new TypedConstructor(typedProgram, constructor, this.className));
|
||||
}
|
||||
|
||||
for (Method method : c.methods()) {
|
||||
|
@ -32,9 +32,14 @@ public class TypedConstructor implements TypedNode {
|
||||
this.typedParameters = typedParameters;
|
||||
this.typedBlock = typedBlock;
|
||||
}
|
||||
public TypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor, String className) {
|
||||
convertToTypedConstructor(typedProgram, unTypedConstructor, className);
|
||||
}
|
||||
|
||||
|
||||
public void convertToTypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor) {
|
||||
public void convertToTypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor, String className) {
|
||||
if(!unTypedConstructor.className().equals(className)) {
|
||||
throw new RuntimeException("Constructor name "+ unTypedConstructor.className() +" must be the same as class name" + className);
|
||||
}
|
||||
name = unTypedConstructor.className();
|
||||
convertToTypedParameter(typedProgram, unTypedConstructor.params());
|
||||
type = Type.VOID;
|
||||
@ -59,9 +64,7 @@ public class TypedConstructor implements TypedNode {
|
||||
return type;
|
||||
}
|
||||
|
||||
public TypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor) {
|
||||
convertToTypedConstructor(typedProgram, unTypedConstructor);
|
||||
}
|
||||
|
||||
|
||||
public boolean isLocalVariablePresent(String localVarName) {
|
||||
return localVariables.stream().anyMatch(localVariable -> localVariable.getName().equals(localVarName));
|
||||
|
Loading…
Reference in New Issue
Block a user