fix type error with returning an array from a subroutine returning uword

This commit is contained in:
Irmen de Jong 2023-07-02 22:09:19 +02:00
parent 0db141eeac
commit f570b70827
3 changed files with 16 additions and 1 deletions

View File

@ -114,6 +114,8 @@ internal class AstChecker(private val program: Program,
if (returnValue == null || returnValue.type != DataType.UBYTE || (returnValue.number!=0.0 && returnValue.number!=1.0)) {
errors.err("type $valueDt of return value doesn't match subroutine's return type ${expectedReturnValues[0]}",returnStmt.value!!.position)
}
} else if(valueDt.isIterable && expectedReturnValues[0]==DataType.UWORD) {
// you can return a string or array when a uword (pointer) is returned
}
else {
errors.err("type $valueDt of return value doesn't match subroutine's return type ${expectedReturnValues[0]}",returnStmt.value!!.position)

View File

@ -320,5 +320,19 @@ other {
compileText(VMTarget(), optimize=false, src, writeAssembly=false) shouldNotBe null
}
test("returning array as uword") {
val src = """
main {
sub start() {
cx16.r0 = getarray()
}
sub getarray() -> uword {
return [11,22,33]
}
}"""
compileText(VMTarget(), optimize=false, src, writeAssembly=false) shouldNotBe null
}
})

View File

@ -1,7 +1,6 @@
TODO
====
- fix type error with returning an array literal from a subroutine returning uword
- fix IR loading of romsubs
romsub $FFD2 = chrout(ubyte ch @ A)
sub start() {