Compare commits

..
4 Commits
Author SHA1 Message Date
dholle 3d456d2ecb Add test case with stackoverflow
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 1m36s
2026-11-18 10:23:02 +01:00
dholle cbfda2da47 Merge pull request 'Fix #436' (#469) from fix-436 into master
SonarQube Scan / SonarQube Trigger (push) Successful in 2m26s
Reviewed-on: #469
2026-11-17 10:41:44 +00:00
dholle c63f1acce5 Implement binary not
Build and Test with Maven / Build-and-test-with-Maven (push) Successful in 1m17s
SonarQube Scan / SonarQube Trigger (pull_request) Successful in 2m27s
2026-11-17 11:22:39 +01:00
dholle c06079058e Fix #436
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 1m56s
SonarQube Scan / SonarQube Trigger (pull_request) Failing after 1m31s
2026-11-17 10:59:28 +01:00
15 changed files with 158 additions and 29 deletions

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
import java.lang.Boolean;
import java.lang.Integer;
import java.lang.System;
import java.io.PrintStream;
public class Bug436 {
public not(Boolean b) {
return !b;
}
public not(Integer i) {
return ~i;
}
}
+96
View File
@@ -0,0 +1,96 @@
// 24 type parameters with 24 typed getters: StackOverflowError in unification (20/20 and 24 params with 18 getters compile)
public class Bug468<
T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20,
T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44> {
public T0 f0;
public T1 f1;
public T2 f2;
public T3 f3;
public T4 f4;
public T5 f5;
public T6 f6;
public T7 f7;
public T8 f8;
public T9 f9;
public T10 f10;
public T11 f11;
public T12 f12;
public T13 f13;
public T14 f14;
public T15 f15;
public T16 f16;
public T17 f17;
public T18 f18;
public T19 f19;
public T20 f20;
public T21 f21;
public T22 f22;
public T23 f23;
public T24 f24;
public T25 f25;
public T26 f26;
public T27 f27;
public T28 f28;
public T29 f29;
public T30 f30;
public T31 f31;
public T32 f32;
public T33 f33;
public T34 f34;
public T35 f35;
public T36 f36;
public T37 f37;
public T38 f38;
public T39 f39;
public T40 f40;
public T41 f41;
public T42 f42;
public T43 f43;
public T44 f44;
public T0 g0() { return f0; }
public T1 g1() { return f1; }
public T2 g2() { return f2; }
public T3 g3() { return f3; }
public T4 g4() { return f4; }
public T5 g5() { return f5; }
public T6 g6() { return f6; }
public T7 g7() { return f7; }
public T8 g8() { return f8; }
public T9 g9() { return f9; }
public T10 g10() { return f10; }
public T11 g11() { return f11; }
public T12 g12() { return f12; }
public T13 g13() { return f13; }
public T14 g14() { return f14; }
public T15 g15() { return f15; }
public T16 g16() { return f16; }
public T17 g17() { return f17; }
public T18 g18() { return f18; }
public T19 g19() { return f19; }
public T20 g20() { return f20; }
public T21 g21() { return f21; }
public T22 g22() { return f22; }
public T23 g23() { return f23; }
public T24 g24() { return f24; }
public T25 g25() { return f25; }
public T26 g26() { return f26; }
public T27 g27() { return f27; }
public T28 g28() { return f28; }
public T29 g29() { return f29; }
public T30 g30() { return f30; }
public T31 g31() { return f31; }
public T32 g32() { return f32; }
public T33 g33() { return f33; }
public T34 g34() { return f34; }
public T35 g35() { return f35; }
public T36 g36() { return f36; }
public T37 g37() { return f37; }
public T38 g38() { return f38; }
public T39 g39() { return f39; }
public T40 g40() { return f40; }
public T41 g41() { return f41; }
public T42 g42() { return f42; }
public T43 g43() { return f43; }
public T44 g44() { return f44; }
}
+4 -7
View File
@@ -13,15 +13,15 @@ public sealed interface LazyList permits Empty, Cons {
public Integer fst();
public LazyList rest();
}
/*
public class Filter {
public LazyList filter(Fun1$$<Integer, Boolean> p, LazyList l) {
/*public LazyList filter(Fun1$$<Integer, Boolean> p, LazyList l) {
return switch(l) {
case Empty e -> e;
case Cons(Integer x, Supplier<LazyList> l1) ->
p.apply(x) ? new Cons(x, () -> filter(p, l1.get())) : filter(p, l1.get());
};
}
}*/
public LazyList filter(Fun1$$<Integer, Boolean> p, Empty()@l) {
return l;
}
@@ -31,8 +31,6 @@ public class Filter {
}
}
*/
//Der Konstruktor Cons muss lazy sein, deshalb hier Supplier<...>
record Cons(Integer x, Fun0$$<LazyList> l) implements LazyList {
public Integer fst() { return this.x; }
@@ -47,7 +45,7 @@ record Empty() implements LazyList {
public LazyList rest() { return null; }
}
/*
class Main {
static LazyList Count(int i) { return new Cons(i, () -> Count(i+1)); }
@@ -56,4 +54,3 @@ class Main {
System.out.println(Count(1).rest().fst());
}
}
*/
+7 -8
View File
@@ -7,10 +7,9 @@ import java.io.PrintStream;
import LazyList;
import Cons;
import Empty;
//import Filter;
import Filter;
public class Primzahlen {
/*
static LazyList from(Integer i) { return new Cons(i, () -> from(i+1)); }
/*LazyList filter(Fun1$$<Integer, Boolean> p, LazyList l) {
@@ -19,7 +18,7 @@ public class Primzahlen {
case Cons(Integer x, Fun0$$<LazyList> l1) ->
p.apply(x) ? new Cons(x, () -> filter(p, l1.apply())) : filter(p, l1.apply());
};
}
}*/
LazyList dropMul(Integer x, LazyList xs) {
return new Filter().filter(y -> (y % x != 0), xs);
@@ -41,13 +40,13 @@ public class Primzahlen {
new Cons(x, () -> take(n-1, l1.apply()));
};
};
*/
public static void main(args) {
//System.out.println(new Cons(1, () -> new Cons(2, () -> new Empty())).fst());
System.out.println(new Cons(1, () -> new Cons(2, () -> new Empty())).fst());
var l = new Cons(1, () -> new Cons(2, () -> new Cons(2, () -> new Empty())));
//System.out.println(l);
//var filtered = new Filter().filter(x -> x == 2, l);
//ystem.out.println(filtered);
System.out.println(l);
var filtered = new Filter().filter(x -> x == 2, l);
System.out.println(filtered);
//System.out.println(from(1).rest().fst());
//Primzahlen pz = new Primzahlen();
//System.out.println(pz.take(10, pz.from(2)));
@@ -735,6 +735,13 @@ public class Codegen {
case TargetUnaryOp.Not not -> {
generate(state, not.expr());
convertTo(state, not.expr().type(), TargetType.boolean_);
mv.visitInsn(ICONST_1);
mv.visitInsn(IXOR);
boxPrimitive(state, TargetType.toPrimitive(not.expr().type()));
}
case TargetUnaryOp.BNot not -> {
generate(state, not.expr());
convertTo(state, not.expr().type(), TargetType.toPrimitive(not.expr().type()));
if (not.type().equals(TargetType.Long)) {
mv.visitLdcInsn(-1L);
mv.visitInsn(LXOR);
@@ -987,6 +987,9 @@ public class StatementGenerator {
} else if (op.getText().equals("-")) {
ret = new UnaryExpr(UnaryExpr.Operation.MINUS, expr, TypePlaceholder.fresh(op), op);
return ret;
} else if (op.getText().equals("~")) {
ret = new UnaryExpr(UnaryExpr.Operation.BNOT, expr, TypePlaceholder.fresh(op), op);
return ret;
} else {
throw new NotImplementedException(op.getText());
}
@@ -1111,7 +1114,7 @@ public class StatementGenerator {
if (expression.lambdaBody().expression() != null) {
List<Statement> statements = new ArrayList<>();
statements.add(new Return(lambdaGenerator.convert(expression.lambdaBody().expression()), expression.lambdaBody().expression().getStart()));
block = new Block(statements, expression.lambdaBody().getStart(), -1);
block = new Block(statements, expression.lambdaBody().getStart());
} else {
block = lambdaGenerator.convert(expression.lambdaBody().block(), true);
}
@@ -14,11 +14,6 @@ public class Block extends Statement {
this.statements = statements;
}
public Block(List<Statement> statements, Token offset, int variance) {
super(TypePlaceholder.fresh(offset, variance, true), offset);
this.statements = statements;
}
public List<Statement> statements = new ArrayList<>();
public List<Statement> getStatements() {
@@ -10,6 +10,7 @@ import org.antlr.v4.runtime.Token;
public class UnaryExpr extends JavaInternalExpression
{
public enum Operation{
BNOT,
NOT,
MINUS,
PREINCREMENT,
@@ -188,10 +188,8 @@ public class OutputGenerator implements ASTVisitor {
@Override
public void visit(LambdaExpression lambdaExpression) {
out.append("(");
lambdaExpression.params.accept(this);
lambdaExpression.params.accept(this);
out.append(" -> ");
out.append("(");
lambdaExpression.methodBody.accept(this);
}
@@ -425,6 +425,7 @@ public class StatementToTargetExpression implements ASTVisitor {
@Override
public void visit(UnaryExpr unaryExpr) {
result = switch (unaryExpr.operation) {
case BNOT -> new TargetUnaryOp.BNot(converter.convert(unaryExpr.getType(), generics), converter.convert(unaryExpr.expr, generics));
case NOT -> new TargetUnaryOp.Not(converter.convert(unaryExpr.getType(), generics), converter.convert(unaryExpr.expr, generics));
case MINUS -> new TargetUnaryOp.Negate(converter.convert(unaryExpr.getType(), generics), converter.convert(unaryExpr.expr, generics));
case PREINCREMENT -> new TargetUnaryOp.PreIncrement(converter.convert(unaryExpr.getType(), generics), converter.convert(unaryExpr.expr, generics));
@@ -7,6 +7,7 @@ public sealed interface TargetUnaryOp extends TargetExpression {
record Negate(TargetType type, TargetExpression expr) implements TargetUnaryOp {}
record Add(TargetType type, TargetExpression expr) implements TargetUnaryOp {}
record BNot(TargetType type, TargetExpression expr) implements TargetUnaryOp {}
record Not(TargetType type, TargetExpression expr) implements TargetUnaryOp {}
record PreIncrement(TargetType type, TargetExpression expr) implements TargetStatementExpression, TargetUnaryOp {}
@@ -254,7 +254,7 @@ public class TYPEStmt implements StatementVisitor {
} else if (unaryExpr.operation == UnaryExpr.Operation.NOT) {
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT, loc(unaryExpr.getOffset())));
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken()), PairOperator.EQUALSDOT, loc(unaryExpr.getOffset())));
} else if (unaryExpr.operation == UnaryExpr.Operation.MINUS) {
} else if (unaryExpr.operation == UnaryExpr.Operation.MINUS || unaryExpr.operation == UnaryExpr.Operation.BNOT) {
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERDOT, loc(unaryExpr.getOffset())));
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT, loc(unaryExpr.getOffset())));
} else {
@@ -39,7 +39,6 @@ public class distributeVariance extends visitUnifyTypeVisitor<Integer> {
List<UnifyType> param = new ArrayList<>(funnty.getTypeParams().get().length);
param.addAll(Arrays.asList(funnty.getTypeParams().get()));
UnifyType resultType = param.remove(param.size()-1);
ht = (ht == 0)? 1 : 0; //bei ht = 0 wird ht auf die Standardwerte für Functionstypes gesetzt
int htInverse = inverseVariance(ht);
param = param.stream()
.map(x -> x.accept(this, htInverse))
+21 -2
View File
@@ -257,7 +257,6 @@ public class TestComplete {
@Test
//@Disabled("This is too complex")
public void matrixTest() throws Exception {
//ConsoleInterface.logLevel = LogLevel.DEBUG;
var classFiles = generateClassFiles(createClassLoader(), "Matrix.jav");
var matrix = classFiles.get("Matrix");
@@ -1360,7 +1359,6 @@ public class TestComplete {
@Disabled("See #405")
@Test
public void testLazy() throws Exception {
ConsoleInterface.logLevel = LogLevel.DEBUG;
var classFiles = generateClassFiles(createClassLoader(), false, "LazyList.jav", "Primzahlen.jav");
var clazz = classFiles.get("Primzahlen");
var main = clazz.getDeclaredMethod("main", List.class);
@@ -1794,4 +1792,25 @@ public class TestComplete {
var len = clazz.getDeclaredMethod("len", L);
assertEquals(3, len.invoke(null, list));
}
@Test
public void testBug436() throws Exception {
var classFiles = generateClassFiles(createClassLoader(), "Bug436.jav");
var clazz = classFiles.get("Bug436");
var instance = clazz.getDeclaredConstructor().newInstance();
var not = clazz.getDeclaredMethod("not", Boolean.class);
assertEquals(false, not.invoke(instance, true));
assertEquals(true, not.invoke(instance, false));
var bnot = clazz.getDeclaredMethod("not", Integer.class);
assertEquals(-11, bnot.invoke(instance, 10));
}
@Test
public void testBug468() throws Exception {
var classFiles = generateClassFiles(createClassLoader(), "Bug468.jav");
var clazz = classFiles.get("Bug468");
var instance = clazz.getDeclaredConstructor().newInstance();
}
}
+1 -1
View File
@@ -143,7 +143,7 @@ public class TestCodegen {
public void testUnary() throws Exception {
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("Unary"));
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "not", List.of(new MethodParameter(TargetType.Integer, "a")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetUnaryOp.Not(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"))))));
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "not", List.of(new MethodParameter(TargetType.Integer, "a")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetUnaryOp.BNot(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"))))));
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "neg", List.of(new MethodParameter(TargetType.Integer, "a")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetUnaryOp.Negate(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"))))));
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "add", List.of(new MethodParameter(TargetType.Integer, "a")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetUnaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"))))));