From d9c387665c9f9c23070b426d8f98b3f61c66f5ef Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Sun, 28 Jun 2020 02:00:02 +0200 Subject: [PATCH] Added test of ranged for loop with an undeclared loop variable. Closes #333 --- .../java/dk/camelot64/kickc/test/TestPrograms.java | 5 +++++ src/test/kc/forranged-npe.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/test/kc/forranged-npe.c diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 0db82edfe..58b709a26 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -3373,6 +3373,11 @@ public class TestPrograms { compileAndCompare("examples/multiplexer/simple-multiplexer.c", 10); } + @Test + public void testForRangedNpe() throws IOException, URISyntaxException { + assertError("forranged-npe.c", "Error! Loop variable not declared i"); + } + @Test public void testForRangedWords() throws IOException, URISyntaxException { compileAndCompare("forrangedwords.c"); diff --git a/src/test/kc/forranged-npe.c b/src/test/kc/forranged-npe.c new file mode 100644 index 000000000..62496c3f3 --- /dev/null +++ b/src/test/kc/forranged-npe.c @@ -0,0 +1,14 @@ +// Range-loop without loop variable declaration causes NPE +// https://gitlab.com/camelot/kickc/-/issues/333 + +char * line = 0x0400; + +void main() { + clear_line(line); + clear_line(line+40); +} + +void clear_line(byte *line) { + for (i: 0..39) + line[i] = 0; +}