Skip to content

Commit 37453da

Browse files
committed
Handle varargs in constructor assurance
1 parent 6c7257c commit 37453da

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtranslation

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtranslation/ClassTranslator.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ private void createConstructFunc(ConstructorDef constr) {
402402
ImExprs arguments = ImExprs(ImVarAccess(thisVar));
403403
for (int i = 0; i < thisCall.getArgs().size(); i++) {
404404
Expr argument = thisCall.getArgs().get(i);
405-
WurstType expectedType = calledConstr.getParameters().get(i).getTyp().attrTyp();
405+
WurstType expectedType = constructorParameterType(calledConstr, i);
406406
arguments.add(ExprTranslation.translateWithExpectedType(
407407
argument, translator, f, expectedType));
408408
}
@@ -439,6 +439,16 @@ private void createConstructFunc(ConstructorDef constr) {
439439
f.getBody().addAll(translator.translateStatements(f, constr.getBody().subList(bodyStartIndex, constr.getBody().size())));
440440
}
441441

442+
private static WurstType constructorParameterType(ConstructorDef constructor, int argumentIndex) {
443+
int lastParameterIndex = constructor.getParameters().size() - 1;
444+
WurstType parameterType = constructor.getParameters()
445+
.get(Math.min(argumentIndex, lastParameterIndex)).getTyp().attrTyp();
446+
if (argumentIndex >= lastParameterIndex && parameterType instanceof WurstTypeVararg) {
447+
return ((WurstTypeVararg) parameterType).getBaseType();
448+
}
449+
return parameterType;
450+
}
451+
442452
private int firstRelevantStatementIndex(ConstructorDef constr) {
443453
for (int i = 0; i < constr.getBody().size(); i++) {
444454
WStatement s = constr.getBody().get(i);

0 commit comments

Comments
 (0)