Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35e8dda6bd | ||
|
|
bf22cf246e | ||
|
|
034cdf2e0b | ||
|
|
95ee84cb99 | ||
|
|
3fc098b155 | ||
|
|
32ddb1132f | ||
|
|
174c999543 | ||
|
|
942b8ca488 |
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
public interface Bug411 {
|
||||||
|
default f() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
public class Bug412 {
|
||||||
|
public m(Integer i) {
|
||||||
|
var r = 0;
|
||||||
|
switch (i) {
|
||||||
|
case 1: r = 10; break;
|
||||||
|
default: r = 20;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
sealed interface L<T> permits Cons, Nil {}
|
||||||
|
public record Cons<T>(T head, L<T> tail) implements L<T> {}
|
||||||
|
public record Nil<T>() implements L<T> {}
|
||||||
|
|
||||||
|
public class Bug416 {
|
||||||
|
public static <T> len(Cons(h, t)) { return 1 + len(t); }
|
||||||
|
public static <T> len(Nil()) { return 0; }
|
||||||
|
}
|
||||||
@@ -1780,7 +1780,7 @@ public class Codegen {
|
|||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
state.scope.parent = parent.scope;
|
state.scope.parent = parent.scope;
|
||||||
}
|
}
|
||||||
var offset = 1;
|
var offset = method.isStatic() ? 0 : 1;
|
||||||
for (var param : method.signature().parameters()) {
|
for (var param : method.signature().parameters()) {
|
||||||
state.createVariable(param.pattern().name(), param.pattern().type());
|
state.createVariable(param.pattern().name(), param.pattern().type());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import de.dhbwstuttgart.typeinference.constraints.Pair;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.PlaceholderRegistry;
|
import de.dhbwstuttgart.typeinference.unify.PlaceholderRegistry;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.*;
|
import de.dhbwstuttgart.typeinference.unify.model.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -54,7 +55,8 @@ public class FCGenerator {
|
|||||||
|
|
||||||
|
|
||||||
private static Boolean isFunctionalInterface(ClassOrInterface cly) {
|
private static Boolean isFunctionalInterface(ClassOrInterface cly) {
|
||||||
return (cly.isInterface() && (cly.isFunctionalInterface() || cly.getMethods().size() == 1));
|
// TODO isFunctionalInterface should be set properly, we shouldn't need to check it again
|
||||||
|
return (cly.isInterface() && (cly.isFunctionalInterface() || cly.getMethods().size() == 1 && Modifier.isAbstract(cly.getMethods().getFirst().modifier)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Pair genImplFunType(ClassOrInterface cly, RefTypeOrTPHOrWildcardOrGeneric fIType, HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs) {
|
private static Pair genImplFunType(ClassOrInterface cly, RefTypeOrTPHOrWildcardOrGeneric fIType, HashMap<String, RefTypeOrTPHOrWildcardOrGeneric> gtvs) {
|
||||||
|
|||||||
@@ -405,14 +405,16 @@ public class StatementGenerator {
|
|||||||
|
|
||||||
private SwitchBlock convert(Java17Parser.SwitchBlockStatementGroupContext stmt) {
|
private SwitchBlock convert(Java17Parser.SwitchBlockStatementGroupContext stmt) {
|
||||||
List<SwitchLabel> labels = new ArrayList<>();
|
List<SwitchLabel> labels = new ArrayList<>();
|
||||||
stmt.switchLabel().forEach((label) -> {
|
var isDefault = false;
|
||||||
|
for (var label : stmt.switchLabel()) {
|
||||||
|
if (label instanceof SwitchLabelDefaultContext) isDefault = true;
|
||||||
labels.add(convert(label));
|
labels.add(convert(label));
|
||||||
});
|
}
|
||||||
List<Statement> block = new ArrayList<>();
|
List<Statement> block = new ArrayList<>();
|
||||||
stmt.blockStatement().stream().forEach((blockStmt) -> {
|
stmt.blockStatement().stream().forEach((blockStmt) -> {
|
||||||
block.addAll(convert(blockStmt));
|
block.addAll(convert(blockStmt));
|
||||||
});
|
});
|
||||||
return new SwitchBlock(labels, new Block(block, stmt.blockStatement(0).getStart()), false, stmt.getStart());
|
return new SwitchBlock(labels, new Block(block, stmt.blockStatement(0).getStart()), isDefault,false, stmt.getStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
private SwitchLabel convert(SwitchLabelContext switchLabel) {
|
private SwitchLabel convert(SwitchLabelContext switchLabel) {
|
||||||
|
|||||||
@@ -409,8 +409,9 @@ public class SyntaxTreeGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isFunctonalInterfce = methods.size() == 1 && Modifier.isAbstract(methods.getFirst().modifier);
|
||||||
var staticCtor = Optional.of(this.generateStaticConstructor(ctx.identifier().getText(), staticFieldInitializations, genericParams, ctx.getStart()));
|
var staticCtor = Optional.of(this.generateStaticConstructor(ctx.identifier().getText(), staticFieldInitializations, genericParams, ctx.getStart()));
|
||||||
return new ClassOrInterface(modifiers, name, fields, Optional.empty(), staticCtor, methods, new ArrayList<>(), genericParams, superClass, true, methods.size() == 1 ? true : false, extendedInterfaces, permittedSubtypes, ctx.getStart(), fileName);
|
return new ClassOrInterface(modifiers, name, fields, Optional.empty(), staticCtor, methods, new ArrayList<>(), genericParams, superClass, true, isFunctonalInterfce, extendedInterfaces, permittedSubtypes, ctx.getStart(), fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GenericDeclarationList createEmptyGenericDeclarationList(Token classNameIdentifier) {
|
private GenericDeclarationList createEmptyGenericDeclarationList(Token classNameIdentifier) {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.objectweb.asm.Opcodes;
|
|||||||
|
|
||||||
import java.lang.classfile.Opcode;
|
import java.lang.classfile.Opcode;
|
||||||
import java.lang.reflect.AccessFlag;
|
import java.lang.reflect.AccessFlag;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -630,7 +631,7 @@ public class ASTToTargetAST {
|
|||||||
mParams,
|
mParams,
|
||||||
classType,
|
classType,
|
||||||
method.name(),
|
method.name(),
|
||||||
false, false, method.isPrivate()
|
method.isStatic(), false, method.isPrivate()
|
||||||
);
|
);
|
||||||
if (method.signature().returnType() != null) {
|
if (method.signature().returnType() != null) {
|
||||||
caseBody = new TargetReturn(caseBody);
|
caseBody = new TargetReturn(caseBody);
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ public class StatementToTargetExpression implements ASTVisitor {
|
|||||||
.map(this::extractAllPatterns)
|
.map(this::extractAllPatterns)
|
||||||
.flatMap(List::stream).toList();
|
.flatMap(List::stream).toList();
|
||||||
case FormalParameter param -> List.of(new TypeVariants(param.getType(), converter.findAllVariants(param.getType())));
|
case FormalParameter param -> List.of(new TypeVariants(param.getType(), converter.findAllVariants(param.getType())));
|
||||||
default -> List.of();
|
case null, default -> List.of();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1759,4 +1759,37 @@ public class TestComplete {
|
|||||||
assertEquals("one", name.invoke(instance, 1));
|
assertEquals("one", name.invoke(instance, 1));
|
||||||
assertEquals("many", name.invoke(instance, 2));
|
assertEquals("many", name.invoke(instance, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBug411() throws Exception {
|
||||||
|
var classFiles = generateClassFiles(createClassLoader(), "Bug411.jav");
|
||||||
|
var clazz = classFiles.get("Bug411");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBug412() throws Exception {
|
||||||
|
var classFiles = generateClassFiles(createClassLoader(), "Bug412.jav");
|
||||||
|
var clazz = classFiles.get("Bug412");
|
||||||
|
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
var m = clazz.getDeclaredMethod("m", Integer.class);
|
||||||
|
assertEquals(10, m.invoke(instance, 1));
|
||||||
|
assertEquals(20, m.invoke(instance, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBug416() throws Exception {
|
||||||
|
var classFiles = generateClassFiles(createClassLoader(), "Bug416.jav");
|
||||||
|
var clazz = classFiles.get("Bug416");
|
||||||
|
var L = classFiles.get("L");
|
||||||
|
var Cons = classFiles.get("Cons");
|
||||||
|
var Nil = classFiles.get("Nil");
|
||||||
|
|
||||||
|
var consCtor = Cons.getDeclaredConstructor(Object.class, L);
|
||||||
|
var nilCtor = Nil.getDeclaredConstructor();
|
||||||
|
|
||||||
|
var list = consCtor.newInstance(1, consCtor.newInstance(2, consCtor.newInstance(3, nilCtor.newInstance())));
|
||||||
|
|
||||||
|
var len = clazz.getDeclaredMethod("len", L);
|
||||||
|
assertEquals(3, len.invoke(null, list));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user