fixed a crash in astchecking of array init values

This commit is contained in:
Irmen de Jong 2020-04-02 18:40:04 +02:00
parent b73da4ed02
commit 2c59cbdece
3 changed files with 5 additions and 5 deletions

View File

@ -82,7 +82,7 @@ internal class AstChecker(private val program: Program,
override fun visit(returnStmt: Return) { override fun visit(returnStmt: Return) {
val expectedReturnValues = returnStmt.definingSubroutine()?.returntypes ?: emptyList() val expectedReturnValues = returnStmt.definingSubroutine()?.returntypes ?: emptyList()
if(expectedReturnValues.size>1) { 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) { if(expectedReturnValues.isEmpty() && returnStmt.value!=null) {
@ -588,7 +588,7 @@ internal class AstChecker(private val program: Program,
val declValue = decl.value val declValue = decl.value
if(declValue!=null && decl.type==VarDeclType.VAR && !declValue.inferType(program).istype(decl.datatype)) 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) super.visit(decl)
} }
@ -1268,7 +1268,7 @@ internal class AstChecker(private val program: Program,
correct = array.all { it in -32768..32767 } correct = array.all { it in -32768..32767 }
} }
DataType.ARRAY_F -> correct = true DataType.ARRAY_F -> correct = true
else -> throw AstException("invalid array type $type") else -> throw FatalAstException("invalid array type $type")
} }
if (!correct) if (!correct)
errors.err("array value out of range for type $type", value.position) errors.err("array value out of range for type $type", value.position)

View File

@ -31,7 +31,7 @@ internal class ExpressionSimplifier(private val program: Program) : AstWalker()
override fun after(assignment: Assignment, parent: Node): Iterable<IAstModification> { override fun after(assignment: Assignment, parent: Node): Iterable<IAstModification> {
if (assignment.aug_op != null) 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() return emptyList()
} }

View File

@ -407,7 +407,7 @@ internal class StatementOptimizer(private val program: Program,
override fun visit(assignment: Assignment): Statement { override fun visit(assignment: Assignment): Statement {
if(assignment.aug_op!=null) 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 isSameAs assignment.value) {
if(assignment.target.isNotMemory(program.namespace)) { if(assignment.target.isNotMemory(program.namespace)) {