From 4640b3104390c1b0afe18601847b4ff266885e7f Mon Sep 17 00:00:00 2001 From: Jesper Gravgaard Date: Sun, 22 Apr 2018 12:22:48 +0200 Subject: [PATCH] Added another test securing that undefined variables cannot be used even if fwd-refs are allowed. --- src/test/java/dk/camelot64/kickc/test/TestPrograms.java | 5 +++++ .../java/dk/camelot64/kickc/test/kc/useuninitialized2.kc | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/test/java/dk/camelot64/kickc/test/kc/useuninitialized2.kc diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index d50c520ff..8d22c6518 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -635,6 +635,11 @@ public class TestPrograms { assertError("useuninitialized", "Variable used before being defined"); } + @Test + public void testUseUninitialized2() throws IOException, URISyntaxException { + assertError("useuninitialized2", "Variable used before being defined"); + } + @Test public void testTypeMismatch() throws IOException, URISyntaxException { assertError("typemismatch", "Type mismatch"); diff --git a/src/test/java/dk/camelot64/kickc/test/kc/useuninitialized2.kc b/src/test/java/dk/camelot64/kickc/test/kc/useuninitialized2.kc new file mode 100644 index 000000000..f47ba6f8c --- /dev/null +++ b/src/test/java/dk/camelot64/kickc/test/kc/useuninitialized2.kc @@ -0,0 +1,9 @@ +// Test that forward-referencing an uninitialized variable inside a method fails. + +void main() { + const byte b = a; + const byte a = 'c'; + byte* screen = $400; + screen[0] = a; + screen[1] = b; +} \ No newline at end of file