mirror of
https://github.com/irmen/prog8.git
synced 2024-11-23 07:32:10 +00:00
added syntax error for non-constant array size declaration
This commit is contained in:
parent
6b5211ad12
commit
260bcd3a55
@ -604,23 +604,28 @@ internal class AstChecker(private val program: Program,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// array length limits
|
// array length limits and constant lenghts
|
||||||
if(decl.isArray) {
|
if(decl.isArray) {
|
||||||
val length = decl.arraysize!!.constIndex() ?: 1
|
val length = decl.arraysize!!.constIndex()
|
||||||
when (decl.datatype) {
|
if(length==null)
|
||||||
DataType.STR, DataType.ARRAY_UB, DataType.ARRAY_B -> {
|
err("array length must be a constant")
|
||||||
if(length==0 || length>256)
|
else {
|
||||||
err("string and byte array length must be 1-256")
|
when (decl.datatype) {
|
||||||
|
DataType.STR, DataType.ARRAY_UB, DataType.ARRAY_B -> {
|
||||||
|
if (length == 0 || length > 256)
|
||||||
|
err("string and byte array length must be 1-256")
|
||||||
|
}
|
||||||
|
DataType.ARRAY_UW, DataType.ARRAY_W -> {
|
||||||
|
if (length == 0 || length > 128)
|
||||||
|
err("word array length must be 1-128")
|
||||||
|
}
|
||||||
|
DataType.ARRAY_F -> {
|
||||||
|
if (length == 0 || length > 51)
|
||||||
|
err("float array length must be 1-51")
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DataType.ARRAY_UW, DataType.ARRAY_W -> {
|
|
||||||
if(length==0 || length>128)
|
|
||||||
err("word array length must be 1-128")
|
|
||||||
}
|
|
||||||
DataType.ARRAY_F -> {
|
|
||||||
if(length==0 || length>51)
|
|
||||||
err("float array length must be 1-51")
|
|
||||||
}
|
|
||||||
else -> {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,12 @@
|
|||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
|
const ubyte size = 100
|
||||||
|
|
||||||
|
ubyte[size+10] bytes
|
||||||
|
|
||||||
txt.print("hello\n")
|
txt.print("hello\n")
|
||||||
|
ubyte dummy = bytes[0]
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user