added syntax error for non-constant array size declaration

This commit is contained in:
Irmen de Jong 2020-12-06 17:02:56 +01:00
parent 6b5211ad12
commit 260bcd3a55
2 changed files with 26 additions and 15 deletions

View File

@ -604,9 +604,12 @@ internal class AstChecker(private val program: Program,
}
}
// array length limits
// array length limits and constant lenghts
if(decl.isArray) {
val length = decl.arraysize!!.constIndex() ?: 1
val length = decl.arraysize!!.constIndex()
if(length==null)
err("array length must be a constant")
else {
when (decl.datatype) {
DataType.STR, DataType.ARRAY_UB, DataType.ARRAY_B -> {
if (length == 0 || length > 256)
@ -620,7 +623,9 @@ internal class AstChecker(private val program: Program,
if (length == 0 || length > 51)
err("float array length must be 1-51")
}
else -> {}
else -> {
}
}
}
}

View File

@ -5,6 +5,12 @@
main {
sub start() {
const ubyte size = 100
ubyte[size+10] bytes
txt.print("hello\n")
ubyte dummy = bytes[0]
}
}