From 08d44ae553951379a6720889498e2214edb8cb11 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 2 Jan 2021 15:40:24 +0100 Subject: [PATCH] fix compiler errors --- .../prog8/ast/processing/VerifyFunctionArgTypes.kt | 12 ++++++++++-- compiler/src/prog8/optimizer/StatementOptimizer.kt | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/compiler/src/prog8/ast/processing/VerifyFunctionArgTypes.kt b/compiler/src/prog8/ast/processing/VerifyFunctionArgTypes.kt index db1a168dc..561fbf280 100644 --- a/compiler/src/prog8/ast/processing/VerifyFunctionArgTypes.kt +++ b/compiler/src/prog8/ast/processing/VerifyFunctionArgTypes.kt @@ -6,6 +6,7 @@ import prog8.ast.Program import prog8.ast.base.DataType import prog8.ast.expressions.Expression import prog8.ast.expressions.FunctionCall +import prog8.ast.expressions.TypecastExpression import prog8.ast.statements.* import prog8.compiler.CompilerException import prog8.functions.BuiltinFunctions @@ -60,8 +61,15 @@ class VerifyFunctionArgTypes(val program: Program) : IAstVisitor { // multiple return values will NOT work inside an expression. // they MIGHT work in a regular assignment or just a function call statement. val parent = if(call is Statement) call.parent else if(call is Expression) call.parent else null - if(call !is FunctionCallStatement && parent !is Assignment && parent !is VarDecl) { - return "can't use subroutine call that returns multiple return values here (try moving it into a separate assignment)" + if (call !is FunctionCallStatement) { + val checkParent = + if(parent is TypecastExpression) + parent.parent + else + parent + if (checkParent !is Assignment && checkParent !is VarDecl) { + return "can't use subroutine call that returns multiple return values here" + } } } } diff --git a/compiler/src/prog8/optimizer/StatementOptimizer.kt b/compiler/src/prog8/optimizer/StatementOptimizer.kt index a69f5d91a..51fc9d429 100644 --- a/compiler/src/prog8/optimizer/StatementOptimizer.kt +++ b/compiler/src/prog8/optimizer/StatementOptimizer.kt @@ -39,7 +39,7 @@ internal class StatementOptimizer(private val program: Program, override fun after(subroutine: Subroutine, parent: Node): Iterable { val forceOutput = "force_output" in subroutine.definingBlock().options() if(subroutine.asmAddress==null && !forceOutput) { - if(subroutine.containsNoCodeNorVars()) { + if(subroutine.containsNoCodeNorVars() && !subroutine.inline) { errors.warn("removing empty subroutine '${subroutine.name}'", subroutine.position) val removals = callgraph.calledBy.getValue(subroutine).map { IAstModification.Remove(it, it.definingScope())