Fix function type addition for if statement
This commit is contained in:
@@ -96,22 +96,25 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
|
|||||||
public Node visitIf_statement(KlangParser.If_statementContext ctx) {
|
public Node visitIf_statement(KlangParser.If_statementContext ctx) {
|
||||||
Node condition = this.visit(ctx.cond);
|
Node condition = this.visit(ctx.cond);
|
||||||
Node thenBlock = this.visit(ctx.then);
|
Node thenBlock = this.visit(ctx.then);
|
||||||
Type type = thenBlock.type;
|
Type type = null;
|
||||||
|
|
||||||
IfStatement result;
|
IfStatement result;
|
||||||
if (ctx.alt != null) {
|
if (ctx.alt != null) {
|
||||||
Node elseBlock = this.visit(ctx.alt);
|
Node elseBlock = this.visit(ctx.alt);
|
||||||
result = new IfStatement((Expression) condition, (Block) thenBlock, (Block) elseBlock);
|
result = new IfStatement((Expression) condition, (Block) thenBlock, (Block) elseBlock);
|
||||||
type = type.combine(elseBlock.type);
|
type = elseBlock.type;
|
||||||
} else if (ctx.elif != null) {
|
} else if (ctx.elif != null) {
|
||||||
Node elif = this.visit(ctx.elif);
|
Node elif = this.visit(ctx.elif);
|
||||||
result = new IfStatement((Expression) condition, (Block) thenBlock, (IfStatement) elif);
|
result = new IfStatement((Expression) condition, (Block) thenBlock, (IfStatement) elif);
|
||||||
type = type.combine(elif.type);
|
type = elif.type;
|
||||||
} else {
|
} else {
|
||||||
result = new IfStatement((Expression) condition, (Block) thenBlock);
|
result = new IfStatement((Expression) condition, (Block) thenBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.type = type;
|
if (thenBlock.type != null && type != null) {
|
||||||
|
result.type = thenBlock.type.combine(type);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user