mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-08-07 06:30:04 +00:00
Fixed NPE if ranged loop-variable is not declared. Closes #333
This commit is contained in:
@@ -1207,6 +1207,9 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
|||||||
addDirectives(lValue, varType, varDirectives, statementSource);
|
addDirectives(lValue, varType, varDirectives, statementSource);
|
||||||
} else {
|
} else {
|
||||||
lValue = getCurrentScope().getVariable(varName);
|
lValue = getCurrentScope().getVariable(varName);
|
||||||
|
if(lValue==null) {
|
||||||
|
throw new CompileError("Error! Loop variable not declared "+varName, statementSource);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exitDeclTypes();
|
exitDeclTypes();
|
||||||
KickCParser.StmtForContext stmtForCtx = (KickCParser.StmtForContext) ctx.getParent();
|
KickCParser.StmtForContext stmtForCtx = (KickCParser.StmtForContext) ctx.getParent();
|
||||||
|
@@ -2410,6 +2410,11 @@ public class TestPrograms {
|
|||||||
compileAndCompare("double-assignment");
|
compileAndCompare("double-assignment");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoopNpe() throws IOException, URISyntaxException {
|
||||||
|
assertError("loop-npe", "Error! Loop variable not declared");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstWordPointer() throws IOException, URISyntaxException {
|
public void testConstWordPointer() throws IOException, URISyntaxException {
|
||||||
compileAndCompare("const-word-pointer");
|
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;
|
||||||
|
}
|
Reference in New Issue
Block a user