mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-30 11:38:38 +00:00
Fixed NPE if ranged loop-variable is not declared. Closes #333
This commit is contained in:
parent
f4206a2e84
commit
812546d603
@ -1207,6 +1207,9 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
||||
addDirectives(lValue, varType, varDirectives, statementSource);
|
||||
} else {
|
||||
lValue = getCurrentScope().getVariable(varName);
|
||||
if(lValue==null) {
|
||||
throw new CompileError("Error! Loop variable not declared "+varName, statementSource);
|
||||
}
|
||||
}
|
||||
exitDeclTypes();
|
||||
KickCParser.StmtForContext stmtForCtx = (KickCParser.StmtForContext) ctx.getParent();
|
||||
|
@ -2410,6 +2410,11 @@ public class TestPrograms {
|
||||
compileAndCompare("double-assignment");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoopNpe() throws IOException, URISyntaxException {
|
||||
assertError("loop-npe", "Error! Loop variable not declared");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstWordPointer() throws IOException, URISyntaxException {
|
||||
compileAndCompare("const-word-pointer");
|
||||
|
13
src/test/kc/loop-npe.kc
Normal file
13
src/test/kc/loop-npe.kc
Normal file
@ -0,0 +1,13 @@
|
||||
// Illustrated compiler NPE when doing ranged loop without declaring the loop variable.
|
||||
|
||||
|
||||
void main() {
|
||||
byte* SCREEN = 0x0400;
|
||||
clear_line(SCREEN);
|
||||
}
|
||||
|
||||
|
||||
void clear_line(byte *line) {
|
||||
for (i: 0..39)
|
||||
line[i] = 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user