From 8e1071aa89caed9e6ea1e15b4133badc23f7bb5b Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 15 Jul 2022 23:17:03 +0200 Subject: [PATCH] fix compiler crashes: txt.chrout("a"), uword[] a = ["ls", subroutine] without & before subroutine. --- .../compiler/astprocessing/AstChecker.kt | 7 +++++-- .../astprocessing/VerifyFunctionArgTypes.kt | 6 ++++-- compiler/test/TestSubroutines.kt | 19 +++++++++++++++++++ docs/source/todo.rst | 2 +- examples/test.p8 | 11 ++++------- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index bf870ff53..4a54a0121 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -799,8 +799,11 @@ internal class AstChecker(private val program: Program, fun isPassByReferenceElement(e: Expression): Boolean { if(e is IdentifierReference) { - val decl = e.targetVarDecl(program)!! - return decl.datatype in PassByReferenceDatatypes + val decl = e.targetVarDecl(program) + return if(decl!=null) + decl.datatype in PassByReferenceDatatypes + else + true // is probably a symbol that needs addr-of } return e is StringLiteral } diff --git a/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt b/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt index 9144355ac..d4483304f 100644 --- a/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt +++ b/compiler/src/prog8/compiler/astprocessing/VerifyFunctionArgTypes.kt @@ -57,8 +57,10 @@ internal class VerifyFunctionArgTypes(val program: Program, val errors: IErrorRe if(mismatch>=0) { val actual = argtypes[mismatch] val expected = consideredParamTypes[mismatch] - if(expected==DataType.BOOL && actual==DataType.UBYTE && call.args[mismatch].constValue(program)?.number !in setOf(0.0, 1.0)) - return Pair("argument ${mismatch + 1} type mismatch, was: $actual expected: $expected", call.args[mismatch].position) + return if(expected==DataType.BOOL && actual==DataType.UBYTE && call.args[mismatch].constValue(program)?.number in setOf(0.0, 1.0)) + null // specifying a 1 or 0 as a BOOL is okay + else + Pair("argument ${mismatch + 1} type mismatch, was: $actual expected: $expected", call.args[mismatch].position) } if(target.isAsmSubroutine) { if(target.asmReturnvaluesRegisters.size>1) { diff --git a/compiler/test/TestSubroutines.kt b/compiler/test/TestSubroutines.kt index 6ffd20a76..41ec0c386 100644 --- a/compiler/test/TestSubroutines.kt +++ b/compiler/test/TestSubroutines.kt @@ -15,6 +15,25 @@ import prog8tests.helpers.compileText class TestSubroutines: FunSpec({ + test("string arg for byte param proper errormessage and subroutineptr in array too") { + val text=""" + main { + sub func(ubyte bb) { + bb++ + } + + sub start() { + func("abc") + uword[] commands = ["abc", func] + } + }""" + val errors = ErrorReporterForTests() + compileText(C64Target(), false, text, writeAssembly = true, errors=errors) shouldBe null + errors.errors.size shouldBe 2 + errors.errors[0] shouldContain "type mismatch, was: STR expected: UBYTE" + errors.errors[1] shouldContain "initialisation value has incompatible type" + } + test("stringParameter") { val text = """ main { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 67b55ad5f..d904be634 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,7 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- txt.chrout("a") -> crash +- conv.any2uword doesn't accept uppercase hex letters - see if we can let for loops skip the loop if end