diff options
| -rw-r--r-- | output/ex22.java | 21 | ||||
| -rw-r--r-- | output/ex23.java | 21 | ||||
| -rw-r--r-- | output/negative/TrickyOverload-error1.java | 21 | ||||
| -rw-r--r-- | output/negative/TrickyOverload-error2.java | 21 | ||||
| -rw-r--r-- | st/SymbolTable.java | 2 | 
5 files changed, 85 insertions, 1 deletions
diff --git a/output/ex22.java b/output/ex22.java new file mode 100644 index 0000000..5d3107e --- /dev/null +++ b/output/ex22.java @@ -0,0 +1,21 @@ +class Overloading { +    public static void main(String[] args) { +        System.out.println(new A().init()); +    } +} + +class A { +    public int init() { +        return 0; +    } + +    public int x(A a) { +        return 1; +    } +} + +class B extends A { +    public int x(B a) { +        return 2; +    } +} diff --git a/output/ex23.java b/output/ex23.java new file mode 100644 index 0000000..a5daf6c --- /dev/null +++ b/output/ex23.java @@ -0,0 +1,21 @@ +class Overriding { +    public static void main(String[] args) { +        System.out.println(new A().init()); +    } +} + +class A { +    public int init() { +        return 0; +    } + +    public int x(A a) { +        return 1; +    } +} + +class B extends A { +    public int x(A a) { +        return 2; +    } +} diff --git a/output/negative/TrickyOverload-error1.java b/output/negative/TrickyOverload-error1.java new file mode 100644 index 0000000..36d1f9c --- /dev/null +++ b/output/negative/TrickyOverload-error1.java @@ -0,0 +1,21 @@ +class Overloading { +    public static void main(String[] args) { +        System.out.println(new A().init()); +    } +} + +class A { +    public int init() { +        return 0; +    } + +    public int x(A a) { +        return 1; +    } +} + +class B extends A { +    public boolean x(A a) { +        return 2; +    } +} diff --git a/output/negative/TrickyOverload-error2.java b/output/negative/TrickyOverload-error2.java new file mode 100644 index 0000000..ee51626 --- /dev/null +++ b/output/negative/TrickyOverload-error2.java @@ -0,0 +1,21 @@ +class Overloading { +    public static void main(String[] args) { +        System.out.println(new A().init()); +    } +} + +class A { +    public int init() { +        return 0; +    } + +    public int x(B a) { +        return 1; +    } +} + +class B extends A { +    public int x(A a) { +        return 2; +    } +} diff --git a/st/SymbolTable.java b/st/SymbolTable.java index ca38295..bd76a13 100644 --- a/st/SymbolTable.java +++ b/st/SymbolTable.java @@ -88,7 +88,7 @@ public class SymbolTable {                                                                 m.getName(),                                                                 cls.getName()));                  for (int i = 0; i < actual.size(); ++i) { -                    if (expected.get(i).getClassInstance() != actual.get(i).getClassInstance()) { +                    if (!expected.get(i).getClassInstance().equals(actual.get(i).getClassInstance())) {                          throw new TypecheckException(String.format("SymbolTable found that %s is overwritten in %s!",                                                                     m.getName(),                                                                     cls.getName()));  | 
