give correct error when using memory mapped var as array pointer

This commit is contained in:
Irmen de Jong 2023-03-11 00:26:19 +01:00
parent a636d3f394
commit f20ca06f85
3 changed files with 28 additions and 6 deletions

View File

@ -112,4 +112,21 @@ class TestAstChecks: FunSpec({
errors.warnings.size shouldBe 0
errors.errors[0] shouldContain "const modifier can only be used"
}
test("array indexing is not allowed on a memory mapped variable") {
val text = """
main {
sub start() {
&ubyte a = 10000
uword z = 500
a[4] = (z % 3) as ubyte
}
}
"""
val errors = ErrorReporterForTests(keepMessagesAfterReporting = true)
compileText(C64Target(), true, text, writeAssembly = true, errors=errors)
errors.errors.size shouldBe 1
errors.warnings.size shouldBe 0
errors.errors[0] shouldContain "indexing requires"
}
})

View File

@ -162,7 +162,8 @@ class TestScoping: FunSpec({
val errors= ErrorReporterForTests()
compileText(C64Target(), false, text, writeAssembly = false, errors = errors) shouldBe null
errors.errors.size shouldBe 1
errors.errors[0] shouldContain "undefined symbol: routine2"
errors.errors[0] shouldContain "undefined"
errors.errors[0] shouldContain "routine2"
}
test("good subroutine calls with qualified names (from root)") {
@ -201,10 +202,14 @@ class TestScoping: FunSpec({
val errors= ErrorReporterForTests()
compileText(C64Target(), false, text, writeAssembly = false, errors=errors) shouldBe null
errors.errors.size shouldBe 4
errors.errors[0] shouldContain "undefined symbol: start.routine2"
errors.errors[1] shouldContain "undefined symbol: wrong.start.routine2"
errors.errors[2] shouldContain "undefined symbol: start.routine2"
errors.errors[3] shouldContain "undefined symbol: wrong.start.routine2"
errors.errors[0] shouldContain "undefined"
errors.errors[0] shouldContain "start.routine2"
errors.errors[1] shouldContain "undefined"
errors.errors[1] shouldContain "wrong.start.routine2"
errors.errors[2] shouldContain "undefined"
errors.errors[2] shouldContain "start.routine2"
errors.errors[3] shouldContain "undefined"
errors.errors[3] shouldContain "wrong.start.routine2"
}
test("good variables without qualified names") {

View File

@ -315,7 +315,7 @@ class ArrayIndexedExpression(var arrayvar: IdentifierReference,
return when (target.datatype) {
DataType.STR, DataType.UWORD -> InferredTypes.knownFor(DataType.UBYTE)
in ArrayDatatypes -> InferredTypes.knownFor(ArrayToElementTypes.getValue(target.datatype))
else -> InferredTypes.unknown()
else -> InferredTypes.knownFor(target.datatype)
}
}
return InferredTypes.unknown()