mirror of
https://github.com/irmen/prog8.git
synced 2024-11-25 19:31:36 +00:00
void syntax check, fixes #135
This commit is contained in:
parent
6e8a89e6f1
commit
62afd3342e
@ -570,6 +570,13 @@ internal class AstChecker(private val program: Program,
|
|||||||
checkType(assignment.target, assignment.value, assignment.isAugmentable)
|
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 fcall = assignment.value as? IFunctionCall
|
||||||
val fcallTarget = fcall?.target?.targetSubroutine(program)
|
val fcallTarget = fcall?.target?.targetSubroutine(program)
|
||||||
|
@ -4,6 +4,7 @@ import io.kotest.core.spec.style.FunSpec
|
|||||||
import io.kotest.matchers.shouldBe
|
import io.kotest.matchers.shouldBe
|
||||||
import io.kotest.matchers.shouldNotBe
|
import io.kotest.matchers.shouldNotBe
|
||||||
import io.kotest.matchers.string.shouldContain
|
import io.kotest.matchers.string.shouldContain
|
||||||
|
import io.kotest.matchers.string.shouldEndWith
|
||||||
import io.kotest.matchers.types.instanceOf
|
import io.kotest.matchers.types.instanceOf
|
||||||
import prog8.ast.IFunctionCall
|
import prog8.ast.IFunctionCall
|
||||||
import prog8.ast.expressions.*
|
import prog8.ast.expressions.*
|
||||||
@ -612,5 +613,30 @@ main {
|
|||||||
}"""
|
}"""
|
||||||
compileText(Cx16Target(), false, src) shouldNotBe null
|
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"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
%import textio
|
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
uword workFunc=$2000
|
void = call($2000)
|
||||||
|
}
|
||||||
void = call(workFunc)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user