summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-05-10 13:11:34 -0600
committerbd-912 <bdunahu@colostate.edu>2024-05-10 13:11:34 -0600
commit4b50a7a2b41373cc9b1644e584886f22da312848 (patch)
tree00e81d06dc29f31c43a2ca73dc19737f7478b31f
parent58fa180a069cef9692f002cb5b5eb401d6c90d0b (diff)
More examples, another small fix for detecting overloads
-rw-r--r--output/ex22.java21
-rw-r--r--output/ex23.java21
-rw-r--r--output/negative/TrickyOverload-error1.java21
-rw-r--r--output/negative/TrickyOverload-error2.java21
-rw-r--r--st/SymbolTable.java2
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()));