Add test for #285 and partially fix it
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 7s

This commit is contained in:
Daniel Holle 2024-03-08 14:00:52 +01:00
parent deeb67c4f7
commit 65a71ebe0c
3 changed files with 26 additions and 2 deletions

View File

@ -0,0 +1,15 @@
import java.util.Optional;
import java.lang.Integer;
class StaticClass {
static StaticClass barbar() {
return new StaticClass();
}
}
public class Bug285 {
void foo() {
Optional<Integer> opt = Optional.empty();
StaticClass b = StaticClass.barbar();
}
}

View File

@ -13,6 +13,7 @@ import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.target.tree.expression.TargetClassName;
import org.antlr.v4.runtime.Token;
import de.dhbwstuttgart.exceptions.NotImplementedException;
@ -772,7 +773,8 @@ public class StatementGenerator {
// gleiche TPH bekommen
var field = fields.get(expression);
return new FieldVar(new This(offset), Modifier.isStatic(field.modifiers()), expression, fields.get(expression).type(), offset);
} else if (reg.contains(expression)) {
return new StaticClassName(reg.getName(expression), offset);
} else {
// lokale Variable wurde ohne "var"-Keyword deklariert und direkt mit Wert versehen
localVars.put(expression, TypePlaceholder.fresh(offset));

View File

@ -876,4 +876,11 @@ public class TestComplete {
var clazz = classFiles.get("Bug112");
var instance = clazz.getDeclaredConstructor().newInstance();
}
@Test
public void testBug285() throws Exception {
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug285.jav");
var clazz = classFiles.get("Bug285");
var instance = clazz.getDeclaredConstructor().newInstance();
}
}