Skip to content

Commit

Permalink
also deal with zero args
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Dec 1, 2021
1 parent b7fffbb commit 5b56e04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 12 additions & 6 deletions compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,23 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter,
private fun visitFunctionCall(call: IFunctionCall) {
when (val target = call.target.targetStatement(program)) {
is Subroutine -> {
if(call.args.size != target.parameters.size)
errors.err("invalid number of arguments", call.args[0].position)
if(call.args.size != target.parameters.size) {
val pos = (if(call.args.any()) call.args[0] else (call as Node)).position
errors.err("invalid number of arguments", pos)
}
}
is BuiltinFunctionStatementPlaceholder -> {
val func = BuiltinFunctions.getValue(target.name)
if(call.args.size != func.parameters.size)
errors.err("invalid number of arguments", call.args[0].position)
if(call.args.size != func.parameters.size) {
val pos = (if(call.args.any()) call.args[0] else (call as Node)).position
errors.err("invalid number of arguments", pos)
}
}
is Label -> {
if(call.args.isNotEmpty())
errors.err("cannot use arguments when calling a label", call.args[0].position)
if(call.args.isNotEmpty()) {
val pos = (if(call.args.any()) call.args[0] else (call as Node)).position
errors.err("cannot use arguments when calling a label", pos)
}
}
null -> {}
else -> throw FatalAstException("weird call target")
Expand Down
4 changes: 4 additions & 0 deletions examples/test.p8
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
%import textio
%import test_stack
%import string
%zeropage dontuse

main {

sub start() {

string.copy()

ubyte @shared dummy
word b1 = 1111
byte b2 = 22
Expand Down

0 comments on commit 5b56e04

Please sign in to comment.