diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 6999701d7..a64fafd51 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -570,6 +570,13 @@ internal class AstChecker(private val program: Program, checkType(assignment.target, assignment.value, assignment.isAugmentable) } + if(assignment.target.void && assignment.target.multi?.isNotEmpty()!=true) { + if(assignment.value is IFunctionCall) + errors.err("cannot assign to 'void', perhaps a void function call was intended", assignment.position) + else + errors.err("cannot assign to 'void'", assignment.position) + return + } val fcall = assignment.value as? IFunctionCall val fcallTarget = fcall?.target?.targetSubroutine(program) diff --git a/compiler/test/ast/TestVariousCompilerAst.kt b/compiler/test/ast/TestVariousCompilerAst.kt index d15bef564..fa1f4149f 100644 --- a/compiler/test/ast/TestVariousCompilerAst.kt +++ b/compiler/test/ast/TestVariousCompilerAst.kt @@ -4,6 +4,7 @@ import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import io.kotest.matchers.string.shouldContain +import io.kotest.matchers.string.shouldEndWith import io.kotest.matchers.types.instanceOf import prog8.ast.IFunctionCall import prog8.ast.expressions.* @@ -612,5 +613,30 @@ main { }""" compileText(Cx16Target(), false, src) shouldNotBe null } + + test("void assignment is invalid") { + val src=""" +main { + romsub $2000 = multi() -> ubyte @A, ubyte @Y + romsub $3000 = single() -> ubyte @A + + sub start() { + void, void = multi() ; ok + cx16.r0L, void = multi() ; ok + void, cx16.r0L = multi() ; ok + void multi() ; ok + void single() ; ok + void = 3333 ; fail! + void = single() ; fail! + void = multi() ; fail! + } +}""" + val errors = ErrorReporterForTests() + compileText(C64Target(), optimize=false, src, writeAssembly=true, errors = errors) shouldBe null + errors.errors.size shouldBe 3 + errors.errors[0] shouldEndWith "cannot assign to 'void'" + errors.errors[1] shouldEndWith "cannot assign to 'void', perhaps a void function call was intended" + errors.errors[2] shouldEndWith "cannot assign to 'void', perhaps a void function call was intended" + } }) diff --git a/examples/test.p8 b/examples/test.p8 index 44a81a645..4080979a8 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,10 +1,7 @@ -%import textio %zeropage basicsafe main { - sub start() { - uword workFunc=$2000 - - void = call(workFunc) - } + sub start() { + void = call($2000) + } }