@@ -9,6 +9,7 @@ import io.kotest.matchers.types.instanceOf
99import prog8.ast.base.DataType
1010import prog8.ast.expressions.*
1111import prog8.ast.statements.*
12+ import prog8.compiler.printProgram
1213import prog8.compiler.target.C64Target
1314import prog8tests.helpers.ErrorReporterForTests
1415import prog8tests.helpers.assertFailure
@@ -262,4 +263,66 @@ class TestSubroutines: FunSpec({
262263 addressExpr.operator shouldBe " +"
263264 (addressExpr.right as NumericLiteralValue ).number.toInt() shouldBe 10
264265 }
266+
267+ test("invalid number of args check on normal subroutine") {
268+ val text="""
269+ main {
270+ sub thing(ubyte a1, ubyte a2) {
271+ }
272+
273+ sub start() {
274+ thing(1)
275+ thing(1,2)
276+ thing(1,2,3)
277+ }
278+ }
279+ """
280+
281+ val errors = ErrorReporterForTests ()
282+ compileText(C64Target , false, text, writeAssembly = false, errors=errors).assertFailure()
283+ errors.errors.size shouldBe 2
284+ errors.errors[0 ] shouldContain " 7:24: invalid number of arguments"
285+ errors.errors[1 ] shouldContain " 9:24: invalid number of arguments"
286+ }
287+
288+ test("invalid number of args check on asm subroutine") {
289+ val text="""
290+ main {
291+ asmsub thing(ubyte a1 @A, ubyte a2 @Y) {
292+ }
293+
294+ sub start() {
295+ thing(1)
296+ thing(1,2)
297+ thing(1,2,3)
298+ }
299+ }
300+ """
301+
302+ val errors = ErrorReporterForTests ()
303+ compileText(C64Target , false, text, writeAssembly = false, errors=errors).assertFailure()
304+ errors.errors.size shouldBe 2
305+ errors.errors[0 ] shouldContain " 7:24: invalid number of arguments"
306+ errors.errors[1 ] shouldContain " 9:24: invalid number of arguments"
307+ }
308+
309+ test("invalid number of args check on call to label and builtin func") {
310+ val text="""
311+ main {
312+ label:
313+ sub start() {
314+ label()
315+ label(1)
316+ void rnd()
317+ void rnd(1)
318+ }
319+ }
320+ """
321+
322+ val errors = ErrorReporterForTests ()
323+ compileText(C64Target , false, text, writeAssembly = false, errors=errors).assertFailure()
324+ errors.errors.size shouldBe 2
325+ errors.errors[0 ] shouldContain " cannot use arguments"
326+ errors.errors[1 ] shouldContain " invalid number of arguments"
327+ }
265328})
0 commit comments