Commit 8d2812d5 authored by uwdkn's avatar uwdkn

Merge branch 'master' into 'master'

Semantic tests from the Rust team

See merge request !35
parents b878acf2 32ef6293
class ArrayLength {
public static void main(String[] args) {
int[] x = new int[23];
/* use of .length is invalid in MiniJava */
int y = x.length;
}
}
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];
}
}
class ExprStmt {
public int foo() {}
public static void main(String[] args) {
foo() + foo();
}
}
class IfElseTypeMismatch {
public static void main(String[] args) {
foo(true);
}
public int foo(boolean b) {
if (b) {
return 42;
} else {
return false;
}
}
}
class InvalidUnreachableCodeIsInvalid {
public static void main(String[] args) {
int x = 5;
return;
/* Unreachable code should still be checked */
boolean b = x;
}
}
class ClassWithNonstaticMain {
/* String is a valid type */
public void main() { }
public void foo() {
main();
}
}
class ClassWithStaticVoidMainStringArgs {
public static void main(String[] args) {
ClassWithNonstaticMain x = new ClassWithNonstaticMain();
x.main();
}
}
/* String shadows the default String class.
* javac won't complain because the proper main method could be defined in another class file.
* However, since MiniJava files contain the entire program, it is reasonable to expect
* that the lack of a proper main method be detected at compile time.
* Analogy:
* If gcc is invoked _without_ '-c' on a set of .c files, gcc will also invoke the linker.
* If the linker cannot find a main, the gcc "user experience" is equivalent to a compiler error.
*/
class String { }
class MainWithLocalStringShadowingJavaString {
public static void main(String[] args) {}
}
class MissingMain {
public int x;
public void foo() {}
}
class Foo {
public Foo Foo;
public Foo Foo(Foo Foo) {
Foo.Foo = new Foo();
return Foo;
}
public static void main(String[] args) {
Foo = Foo(new Foo());
}
}
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];
}
}
class SystemShadowing {
public SystemShadowing System;
public SystemShadowing out;
public void println(int x) { }
public void nonstatic() {
System.out.println(23);
}
public static void main(String[] args) {
SystemShadowing x = new SystemShadowing();
x.nonstatic(); /* expected to throw NullPointerException at runtime due to shadowing */
}
}
class VoidField {
public void foo;
public static void main(String[] args) {
}
}
class VoidParam {
public static void main(String[] args) { }
public void foo(void param) {}
}
class VoidVar {
public static void main(String[] args) {
void foo;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment