diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass1TypeInference.java b/src/main/java/dk/camelot64/kickc/passes/Pass1TypeInference.java index b0eb55178..bb3f8a629 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass1TypeInference.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass1TypeInference.java @@ -54,7 +54,7 @@ public class Pass1TypeInference extends Pass1Base { Procedure procedure = scopes.peek().getProcedure(procedureName); call.setProcedure(procedure.getRef()); if(procedure.getParameters().size()!=call.getParameters().size()) { - throw new RuntimeException("Wrong number of parameters in call. Expected " +procedure.getParameters().size()+". "+statement.toString()); + throw new CompileError("Wrong number of parameters in call. Expected " +procedure.getParameters().size()+". "+statement.toString()); } if(lValue instanceof VariableRef) { Variable lValueVar = programScope.getVariable((VariableRef) lValue); diff --git a/src/main/java/dk/camelot64/kickc/test/TestPrograms.java b/src/main/java/dk/camelot64/kickc/test/TestPrograms.java index cffa8149e..fa79e2cf2 100644 --- a/src/main/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/main/java/dk/camelot64/kickc/test/TestPrograms.java @@ -307,6 +307,27 @@ public class TestPrograms extends TestCase { fail("Expected compile error."); } + public void testToManyParams() throws IOException, URISyntaxException { + try { + compileAndCompare("tomanyparams"); + } catch (CompileError e) { + // expecting error! + return; + } + fail("Expected compile error."); + } + + public void testToFewParams() throws IOException, URISyntaxException { + try { + compileAndCompare("tofewparams"); + } catch (CompileError e) { + // expecting error! + return; + } + fail("Expected compile error."); + } + + private void compileAndCompare(String filename) throws IOException, URISyntaxException { TestPrograms tester = new TestPrograms(); diff --git a/src/main/java/dk/camelot64/kickc/test/tofewparams.kc b/src/main/java/dk/camelot64/kickc/test/tofewparams.kc new file mode 100644 index 000000000..926bdeaca --- /dev/null +++ b/src/main/java/dk/camelot64/kickc/test/tofewparams.kc @@ -0,0 +1,12 @@ + +void main() { + plot(5,5); + plot(5); +} + + +void plot(byte x, byte y) { + const byte* screen = $0400; + byte* pos = screen+x+y; + *pos = 1; +} \ No newline at end of file diff --git a/src/main/java/dk/camelot64/kickc/test/tomanyparams.kc b/src/main/java/dk/camelot64/kickc/test/tomanyparams.kc new file mode 100644 index 000000000..0a82a1c4f --- /dev/null +++ b/src/main/java/dk/camelot64/kickc/test/tomanyparams.kc @@ -0,0 +1,12 @@ + +void main() { + plot(5,5); + plot(5,5,5); +} + + +void plot(byte x, byte y) { + const byte* screen = $0400; + byte* pos = screen+x+y; + *pos = 1; +} \ No newline at end of file