Fix null literal
This commit is contained in:
parent
a035589647
commit
dcfafe5995
3
resources/bytecode/javFiles/Literal.jav
Normal file
3
resources/bytecode/javFiles/Literal.jav
Normal file
@ -0,0 +1,3 @@
|
||||
public class Literal {
|
||||
m() { return null; }
|
||||
}
|
@ -806,6 +806,7 @@ public class Codegen {
|
||||
case StringLiteral stringLiteral -> mv.visitLdcInsn(stringLiteral.value());
|
||||
case CharLiteral charLiteral -> mv.visitIntInsn(BIPUSH, charLiteral.value());
|
||||
case DoubleLiteral doubleLiteral -> mv.visitLdcInsn(doubleLiteral.value());
|
||||
case Null ignored -> mv.visitInsn(ACONST_NULL);
|
||||
case BooleanLiteral booleanLiteral -> {
|
||||
if (booleanLiteral.value()) {
|
||||
mv.visitInsn(ICONST_1);
|
||||
|
@ -320,6 +320,8 @@ public class StatementToTargetExpression implements ASTVisitor {
|
||||
result = new TargetLiteral.StringLiteral((String) literal.value);
|
||||
} else if (literal.value instanceof Boolean) {
|
||||
result = new TargetLiteral.BooleanLiteral((boolean) literal.value);
|
||||
} else if (literal.value == null) {
|
||||
result = new TargetLiteral.Null();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,4 +53,16 @@ public sealed interface TargetLiteral extends TargetExpression {
|
||||
return TargetType.String;
|
||||
}
|
||||
}
|
||||
|
||||
record Null() implements TargetLiteral {
|
||||
@Override
|
||||
public TargetType type() {
|
||||
return TargetType.Object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object value() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -451,7 +451,8 @@ public class TYPEStmt implements StatementVisitor {
|
||||
if (literal.value instanceof Boolean) {
|
||||
constraintsSet.addUndConstraint(new Pair(literal.getType(), bool, PairOperator.EQUALSDOT));
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
if (literal.value != null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
@ -816,4 +816,13 @@ public class TestComplete {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiteral() throws Exception {
|
||||
var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Literal.jav");
|
||||
var clazz = classFiles.get("Literal");
|
||||
var instance = clazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
assertNull(clazz.getDeclaredMethod("m").invoke(instance));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user