mirror of
https://github.com/irmen/prog8.git
synced 2025-01-23 15:30:10 +00:00
fix crash when using undefined variable in for loop
This commit is contained in:
parent
96bed8f57f
commit
2e303041c1
@ -186,7 +186,7 @@ internal class AstChecker(private val program: Program,
|
||||
}
|
||||
}
|
||||
|
||||
val iterableDt = forLoop.iterable.inferType(program).getOr(DataType.forDt(BaseDataType.BYTE))
|
||||
val iterableDt = forLoop.iterable.inferType(program).getOrUndef()
|
||||
|
||||
if(iterableDt.isNumeric) TODO("iterable type should not be simple numeric!? "+forLoop.position) // TODO
|
||||
|
||||
|
@ -1015,6 +1015,24 @@ main {
|
||||
val handler = sub.children[8] as PtSub
|
||||
handler.name shouldBe "p8s_prog8_invoke_defers"
|
||||
}
|
||||
|
||||
test("unknown variable in for loop gives proper errors") {
|
||||
val src="""
|
||||
main {
|
||||
sub start() {
|
||||
ubyte i
|
||||
for i in 0 to count - 1 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}"""
|
||||
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), optimize=false, src, writeAssembly=false, errors = errors) shouldBe null
|
||||
errors.errors.size shouldBe 3
|
||||
errors.errors[0] shouldContain "loop variable can only loop over"
|
||||
errors.errors[1] shouldContain "undefined symbol"
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
@ -241,6 +241,10 @@ class BinaryExpression(
|
||||
companion object {
|
||||
fun commonDatatype(leftDt: DataType, rightDt: DataType,
|
||||
left: Expression?, right: Expression?): Pair<DataType, Expression?> {
|
||||
|
||||
if(leftDt.isUndefined || rightDt.isUndefined)
|
||||
return DataType.forDt(BaseDataType.UNDEFINED) to null
|
||||
|
||||
// byte + byte -> byte
|
||||
// byte + word -> word
|
||||
// word + byte -> word
|
||||
|
Loading…
x
Reference in New Issue
Block a user