Type inference for switch
This commit is contained in:
parent
762d344e42
commit
14d0475d59
@ -5,7 +5,7 @@ import java.lang.Float;
|
|||||||
record Rec(Integer a, Object b) {}
|
record Rec(Integer a, Object b) {}
|
||||||
|
|
||||||
public class Switch {
|
public class Switch {
|
||||||
Integer main(Object o) {
|
main(o) {
|
||||||
return switch (o) {
|
return switch (o) {
|
||||||
case Rec(Integer a, Integer b) -> { yield a + b; }
|
case Rec(Integer a, Integer b) -> { yield a + b; }
|
||||||
case Rec(Integer a, Float b) -> { yield a + 10; }
|
case Rec(Integer a, Float b) -> { yield a + 10; }
|
||||||
|
@ -735,6 +735,9 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
public void visit(Switch switchStmt) {
|
public void visit(Switch switchStmt) {
|
||||||
switchStack.push(switchStmt);
|
switchStack.push(switchStmt);
|
||||||
for (var child : switchStmt.getBlocks()) {
|
for (var child : switchStmt.getBlocks()) {
|
||||||
|
for (var label : child.getLabels()) if (label.getExpression() instanceof Pattern)
|
||||||
|
constraintsSet.addUndConstraint(new Pair(label.getExpression().getType(), switchStmt.getSwitch().getType(), PairOperator.SMALLERDOT));
|
||||||
|
|
||||||
child.accept(this);
|
child.accept(this);
|
||||||
constraintsSet.addUndConstraint(new Pair(child.getType(), switchStmt.getType(), PairOperator.SMALLERDOT));
|
constraintsSet.addUndConstraint(new Pair(child.getType(), switchStmt.getType(), PairOperator.SMALLERDOT));
|
||||||
}
|
}
|
||||||
@ -756,7 +759,7 @@ public class TYPEStmt implements StatementVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public void visit(Yield aYield) {
|
public void visit(Yield aYield) {
|
||||||
aYield.retexpr.accept(this);
|
aYield.retexpr.accept(this);
|
||||||
constraintsSet.addUndConstraint(new Pair(aYield.getType(), switchStack.peek().getType(), PairOperator.SMALLERDOT));
|
constraintsSet.addUndConstraint(new Pair(aYield.getType(), switchStack.peek().getType(), PairOperator.EQUALSDOT));
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user