1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-12-19 15:29:48 +00:00

Added tests for to few and many method parameters

This commit is contained in:
jespergravgaard 2017-12-03 17:01:23 +01:00
parent 87f58d8782
commit 878d3ae36b
4 changed files with 46 additions and 1 deletions

View File

@ -54,7 +54,7 @@ public class Pass1TypeInference extends Pass1Base {
Procedure procedure = scopes.peek().getProcedure(procedureName); Procedure procedure = scopes.peek().getProcedure(procedureName);
call.setProcedure(procedure.getRef()); call.setProcedure(procedure.getRef());
if(procedure.getParameters().size()!=call.getParameters().size()) { 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) { if(lValue instanceof VariableRef) {
Variable lValueVar = programScope.getVariable((VariableRef) lValue); Variable lValueVar = programScope.getVariable((VariableRef) lValue);

View File

@ -307,6 +307,27 @@ public class TestPrograms extends TestCase {
fail("Expected compile error."); 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 { private void compileAndCompare(String filename) throws IOException, URISyntaxException {
TestPrograms tester = new TestPrograms(); TestPrograms tester = new TestPrograms();

View File

@ -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;
}

View File

@ -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;
}