From 758fdf5a3d6508fdd826476ac638614f9aac394e Mon Sep 17 00:00:00 2001 From: bd-912 Date: Fri, 10 May 2024 13:37:18 -0600 Subject: Fix introduced error with ClassInstance.equals double usage --- heat/TypeBundle.java | 4 ++-- st/ClassInstance.java | 6 ++++++ st/SymbolTable.java | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/heat/TypeBundle.java b/heat/TypeBundle.java index 1867e0d..b484cc4 100644 --- a/heat/TypeBundle.java +++ b/heat/TypeBundle.java @@ -29,8 +29,8 @@ class TypeBundle { return (other instanceof TypeBundle) && (tb = (TypeBundle) other).type == this.type && (tb.instance == this.instance || - (tb.instance != null && tb.instance.getExtend() != null && - tb.instance.getExtend().equals(this.instance))); + (tb.instance != null && + tb.instance.equalsOnExtend(this.instance))); } public boolean isClass() { diff --git a/st/ClassInstance.java b/st/ClassInstance.java index a794f96..a7a4500 100644 --- a/st/ClassInstance.java +++ b/st/ClassInstance.java @@ -15,6 +15,12 @@ public class ClassInstance extends AbstractInstance { } @Override public boolean equals(Object other) { + ClassInstance o; + return (other instanceof ClassInstance && + ((o = (ClassInstance) other).getName() == this.getName())); + } + + public boolean equalsOnExtend(Object other) { ClassInstance o; if (other instanceof ClassInstance) o = (ClassInstance) other; diff --git a/st/SymbolTable.java b/st/SymbolTable.java index bd76a13..63832e6 100644 --- a/st/SymbolTable.java +++ b/st/SymbolTable.java @@ -83,12 +83,12 @@ public class SymbolTable { ArrayList expected = exist.getArguments(); ArrayList actual = m.getArguments(); if (expected.size() != actual.size() || - !exist.getReturn().equals(m.getReturn())) + !exist.getReturn().equalsOnExtend(m.getReturn())) throw new TypecheckException(String.format("SymbolTable found that %s is overwritten in %s!", m.getName(), cls.getName())); for (int i = 0; i < actual.size(); ++i) { - if (!expected.get(i).getClassInstance().equals(actual.get(i).getClassInstance())) { + if (!expected.get(i).getClassInstance().equalsOnExtend(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