From b1be18f367ee1e74284b51c9a6a7b341a619df63 Mon Sep 17 00:00:00 2001 From: Marvin Kaiser Date: Mon, 27 Jan 2020 16:47:00 +0100 Subject: [PATCH] Fix function type addition for if statement --- .../java/de/hsrm/compiler/Klang/ContextAnalysis.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/hsrm/compiler/Klang/ContextAnalysis.java b/src/main/java/de/hsrm/compiler/Klang/ContextAnalysis.java index 73acc9d..7ab4084 100644 --- a/src/main/java/de/hsrm/compiler/Klang/ContextAnalysis.java +++ b/src/main/java/de/hsrm/compiler/Klang/ContextAnalysis.java @@ -96,22 +96,25 @@ public class ContextAnalysis extends KlangBaseVisitor { public Node visitIf_statement(KlangParser.If_statementContext ctx) { Node condition = this.visit(ctx.cond); Node thenBlock = this.visit(ctx.then); - Type type = thenBlock.type; + Type type = null; IfStatement result; if (ctx.alt != null) { Node elseBlock = this.visit(ctx.alt); result = new IfStatement((Expression) condition, (Block) thenBlock, (Block) elseBlock); - type = type.combine(elseBlock.type); + type = elseBlock.type; } else if (ctx.elif != null) { Node elif = this.visit(ctx.elif); result = new IfStatement((Expression) condition, (Block) thenBlock, (IfStatement) elif); - type = type.combine(elif.type); + type = elif.type; } else { result = new IfStatement((Expression) condition, (Block) thenBlock); } - result.type = type; + if (thenBlock.type != null && type != null) { + result.type = thenBlock.type.combine(type); + } + return result; }