mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
fix problem with initializing certain array decls with single value
This commit is contained in:
parent
f20ca06f85
commit
ed597423cd
@ -626,8 +626,15 @@ internal class AstChecker(private val program: Program,
|
|||||||
|
|
||||||
val declValue = decl.value
|
val declValue = decl.value
|
||||||
if(declValue!=null && decl.type==VarDeclType.VAR) {
|
if(declValue!=null && decl.type==VarDeclType.VAR) {
|
||||||
if (declValue.inferType(program) isnot decl.datatype) {
|
val iDt = declValue.inferType(program)
|
||||||
err("initialisation value has incompatible type (${declValue.inferType(program)}) for the variable (${decl.datatype})")
|
if (iDt isnot decl.datatype) {
|
||||||
|
if(decl.datatype in ArrayDatatypes) {
|
||||||
|
val eltDt = ArrayToElementTypes.getValue(decl.datatype)
|
||||||
|
if(iDt isnot eltDt)
|
||||||
|
err("initialisation value has incompatible type (${declValue.inferType(program)}) for the variable (${decl.datatype})")
|
||||||
|
} else {
|
||||||
|
err("initialisation value has incompatible type (${declValue.inferType(program)}) for the variable (${decl.datatype})")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1462,6 +1469,10 @@ internal class AstChecker(private val program: Program,
|
|||||||
DataType.BOOL -> {
|
DataType.BOOL -> {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
in ArrayDatatypes -> {
|
||||||
|
val eltDt = ArrayToElementTypes.getValue(targetDt)
|
||||||
|
return checkValueTypeAndRange(eltDt, value)
|
||||||
|
}
|
||||||
else -> return err("value of type ${value.type} not compatible with $targetDt")
|
else -> return err("value of type ${value.type} not compatible with $targetDt")
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -129,4 +129,20 @@ class TestAstChecks: FunSpec({
|
|||||||
errors.warnings.size shouldBe 0
|
errors.warnings.size shouldBe 0
|
||||||
errors.errors[0] shouldContain "indexing requires"
|
errors.errors[0] shouldContain "indexing requires"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("array decl with expression as size can be initialized with a single value") {
|
||||||
|
val text = """
|
||||||
|
main {
|
||||||
|
sub start() {
|
||||||
|
const ubyte n = 40
|
||||||
|
const ubyte half = n / 2
|
||||||
|
ubyte[half] @shared a = 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
val errors = ErrorReporterForTests(keepMessagesAfterReporting = true)
|
||||||
|
compileText(C64Target(), true, text, writeAssembly = true, errors=errors) shouldNotBe null
|
||||||
|
errors.errors.size shouldBe 0
|
||||||
|
errors.warnings.size shouldBe 0
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user