Add test for #285 and partially fix it
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 7s
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 7s
This commit is contained in:
parent
deeb67c4f7
commit
65a71ebe0c
15
resources/bytecode/javFiles/Bug285.jav
Normal file
15
resources/bytecode/javFiles/Bug285.jav
Normal 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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
@ -769,10 +770,11 @@ public class StatementGenerator {
|
||||
if (localVars.get(expression) != null) {
|
||||
return new LocalVar(expression, localVars.get(expression), offset);
|
||||
} else if (fields.get(expression) != null) {// PL 2018-11-01 fields eingefuegt, damit die fields immer die
|
||||
// gleiche TPH bekommen
|
||||
// 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));
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user