From 4b78c8d3992b07d03064b38b1c5f88a22f5bf8b0 Mon Sep 17 00:00:00 2001 From: Joshua Bachmeier Date: Thu, 15 Nov 2018 16:47:41 +0100 Subject: [PATCH] More tests --- expression_statement.invalid.java | 6 ++++++ semantic/array_out_of_bounds.java | 7 +++++++ semantic/namespaces.java | 12 ++++++++++++ semantic/new_array_access.mj | 9 +++++++++ 4 files changed, 34 insertions(+) create mode 100644 expression_statement.invalid.java create mode 100644 semantic/array_out_of_bounds.java create mode 100644 semantic/namespaces.java create mode 100644 semantic/new_array_access.mj diff --git a/expression_statement.invalid.java b/expression_statement.invalid.java new file mode 100644 index 0000000..8c2106e --- /dev/null +++ b/expression_statement.invalid.java @@ -0,0 +1,6 @@ +class ExprStmt { + public int foo() {} + public static void main(String[] args) { + foo() + foo(); + } +} diff --git a/semantic/array_out_of_bounds.java b/semantic/array_out_of_bounds.java new file mode 100644 index 0000000..898e6f0 --- /dev/null +++ b/semantic/array_out_of_bounds.java @@ -0,0 +1,7 @@ +class ArrayOutOfBounds { + public static void main(String[] args) { + int[] x = new int[5]; + /* This is a runtime error, the compiler shouldn't care */ + int y = x[10]; + } +} diff --git a/semantic/namespaces.java b/semantic/namespaces.java new file mode 100644 index 0000000..3ef1b4a --- /dev/null +++ b/semantic/namespaces.java @@ -0,0 +1,12 @@ +class Foo { + Foo Foo; + + Foo Foo(Foo Foo) { + Foo.Foo = new Foo(); + return Foo; + } + + public static void main(String[] args) { + Foo = Foo(new Foo()); + } +} diff --git a/semantic/new_array_access.mj b/semantic/new_array_access.mj new file mode 100644 index 0000000..6b91d04 --- /dev/null +++ b/semantic/new_array_access.mj @@ -0,0 +1,9 @@ +class NewArrayAccess { + public static void main(String[] args) { + /* + * In Java, this is invalid, since this creates a new 2D array (which is not the type of x) + * In MiniJava, this is valid, because this creates a new array of size 5 and access the first element + */ + int x = new int[5][1]; + } +} -- GitLab