Skip to content

Commit 5b56e04

Browse files
committed
also deal with zero args
1 parent b7fffbb commit 5b56e04

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

compiler/src/prog8/compiler/astprocessing/AstIdentifiersChecker.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,23 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter,
135135
private fun visitFunctionCall(call: IFunctionCall) {
136136
when (val target = call.target.targetStatement(program)) {
137137
is Subroutine -> {
138-
if(call.args.size != target.parameters.size)
139-
errors.err("invalid number of arguments", call.args[0].position)
138+
if(call.args.size != target.parameters.size) {
139+
val pos = (if(call.args.any()) call.args[0] else (call as Node)).position
140+
errors.err("invalid number of arguments", pos)
141+
}
140142
}
141143
is BuiltinFunctionStatementPlaceholder -> {
142144
val func = BuiltinFunctions.getValue(target.name)
143-
if(call.args.size != func.parameters.size)
144-
errors.err("invalid number of arguments", call.args[0].position)
145+
if(call.args.size != func.parameters.size) {
146+
val pos = (if(call.args.any()) call.args[0] else (call as Node)).position
147+
errors.err("invalid number of arguments", pos)
148+
}
145149
}
146150
is Label -> {
147-
if(call.args.isNotEmpty())
148-
errors.err("cannot use arguments when calling a label", call.args[0].position)
151+
if(call.args.isNotEmpty()) {
152+
val pos = (if(call.args.any()) call.args[0] else (call as Node)).position
153+
errors.err("cannot use arguments when calling a label", pos)
154+
}
149155
}
150156
null -> {}
151157
else -> throw FatalAstException("weird call target")

examples/test.p8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
%import textio
22
%import test_stack
3+
%import string
34
%zeropage dontuse
45

56
main {
67

78
sub start() {
9+
10+
string.copy()
11+
812
ubyte @shared dummy
913
word b1 = 1111
1014
byte b2 = 22

0 commit comments

Comments
 (0)