From 2c59cbdece1f598397a54c87e1ad79a1d989895d Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 2 Apr 2020 18:40:04 +0200 Subject: [PATCH] fixed a crash in astchecking of array init values --- compiler/src/prog8/ast/processing/AstChecker.kt | 6 +++--- compiler/src/prog8/optimizer/ExpressionSimplifier.kt | 2 +- compiler/src/prog8/optimizer/StatementOptimizer.kt | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/src/prog8/ast/processing/AstChecker.kt b/compiler/src/prog8/ast/processing/AstChecker.kt index fa3852784..1fa20c3b4 100644 --- a/compiler/src/prog8/ast/processing/AstChecker.kt +++ b/compiler/src/prog8/ast/processing/AstChecker.kt @@ -82,7 +82,7 @@ internal class AstChecker(private val program: Program, override fun visit(returnStmt: Return) { val expectedReturnValues = returnStmt.definingSubroutine()?.returntypes ?: emptyList() if(expectedReturnValues.size>1) { - throw AstException("cannot use a return with one value in a subroutine that has multiple return values: $returnStmt") + throw FatalAstException("cannot use a return with one value in a subroutine that has multiple return values: $returnStmt") } if(expectedReturnValues.isEmpty() && returnStmt.value!=null) { @@ -588,7 +588,7 @@ internal class AstChecker(private val program: Program, val declValue = decl.value if(declValue!=null && decl.type==VarDeclType.VAR && !declValue.inferType(program).istype(decl.datatype)) - throw FatalAstException("initialisation value $declValue is of different type (${declValue.inferType(program)} as the variable (${decl.datatype}) at ${decl.position}") + err("initialisation value has incompatible type (${declValue.inferType(program)}) for the variable (${decl.datatype})", declValue.position) super.visit(decl) } @@ -1268,7 +1268,7 @@ internal class AstChecker(private val program: Program, correct = array.all { it in -32768..32767 } } DataType.ARRAY_F -> correct = true - else -> throw AstException("invalid array type $type") + else -> throw FatalAstException("invalid array type $type") } if (!correct) errors.err("array value out of range for type $type", value.position) diff --git a/compiler/src/prog8/optimizer/ExpressionSimplifier.kt b/compiler/src/prog8/optimizer/ExpressionSimplifier.kt index 0238b7e26..7bdb25df1 100644 --- a/compiler/src/prog8/optimizer/ExpressionSimplifier.kt +++ b/compiler/src/prog8/optimizer/ExpressionSimplifier.kt @@ -31,7 +31,7 @@ internal class ExpressionSimplifier(private val program: Program) : AstWalker() override fun after(assignment: Assignment, parent: Node): Iterable { if (assignment.aug_op != null) - throw AstException("augmented assignments should have been converted to normal assignments before this optimizer: $assignment") + throw FatalAstException("augmented assignments should have been converted to normal assignments before this optimizer: $assignment") return emptyList() } diff --git a/compiler/src/prog8/optimizer/StatementOptimizer.kt b/compiler/src/prog8/optimizer/StatementOptimizer.kt index b8ef9c198..5b283c333 100644 --- a/compiler/src/prog8/optimizer/StatementOptimizer.kt +++ b/compiler/src/prog8/optimizer/StatementOptimizer.kt @@ -407,7 +407,7 @@ internal class StatementOptimizer(private val program: Program, override fun visit(assignment: Assignment): Statement { if(assignment.aug_op!=null) - throw AstException("augmented assignments should have been converted to normal assignments before this optimizer: $assignment") + throw FatalAstException("augmented assignments should have been converted to normal assignments before this optimizer: $assignment") if(assignment.target isSameAs assignment.value) { if(assignment.target.isNotMemory(program.namespace)) {