From 1298a32801f12cc20b5a706377443d557e8da9b6 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Fri, 10 May 2024 14:25:06 -0600 Subject: Require parameters to match exactly in SymbolTable for non-overwrite --- output/negative/FailedOverride-error.java | 21 +++++++++++++++++++++ st/SymbolTable.java | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 output/negative/FailedOverride-error.java diff --git a/output/negative/FailedOverride-error.java b/output/negative/FailedOverride-error.java new file mode 100644 index 0000000..9ffac74 --- /dev/null +++ b/output/negative/FailedOverride-error.java @@ -0,0 +1,21 @@ +class FailedOverrride { + 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/st/SymbolTable.java b/st/SymbolTable.java index 63832e6..0fca239 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().equalsOnExtend(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())); -- cgit v1.2.3