mirror of
https://github.com/irmen/prog8.git
synced 2024-10-04 12:57:29 +00:00
give correct error on attempt to const array
This commit is contained in:
parent
043df18daa
commit
a636d3f394
@ -87,6 +87,10 @@ internal class ConstantIdentifierReplacer(private val program: Program, private
|
|||||||
if(forloop!=null && identifier===forloop.loopVar)
|
if(forloop!=null && identifier===forloop.loopVar)
|
||||||
return noModifications
|
return noModifications
|
||||||
|
|
||||||
|
val dt = identifier.inferType(program)
|
||||||
|
if(!dt.isKnown || !dt.isNumeric)
|
||||||
|
return noModifications
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val cval = identifier.constValue(program) ?: return noModifications
|
val cval = identifier.constValue(program) ?: return noModifications
|
||||||
return when (cval.type) {
|
return when (cval.type) {
|
||||||
|
@ -96,4 +96,20 @@ class TestAstChecks: FunSpec({
|
|||||||
"""
|
"""
|
||||||
compileText(C64Target(), false, text, writeAssembly = false) shouldNotBe null
|
compileText(C64Target(), false, text, writeAssembly = false) shouldNotBe null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("const is not allowed on arrays") {
|
||||||
|
val text = """
|
||||||
|
main {
|
||||||
|
sub start() {
|
||||||
|
const ubyte[5] a = 5
|
||||||
|
a[2]=42
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
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 "const modifier can only be used"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user