diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 534cc68e4..2eb1d79b1 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -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) diff --git a/compiler/test/ast/TestVariousCompilerAst.kt b/compiler/test/ast/TestVariousCompilerAst.kt index c18a63179..9b54649c4 100644 --- a/compiler/test/ast/TestVariousCompilerAst.kt +++ b/compiler/test/ast/TestVariousCompilerAst.kt @@ -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 + } }) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 9572fcc25..2c8d29d7d 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -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() {