From 297d7292bf8b42eda443ad65b618a697f7ef67ad Mon Sep 17 00:00:00 2001 From: bd-912 Date: Sun, 12 May 2024 19:26:57 -0600 Subject: Unconfirmed fix for recursive-extension finder --- st/ClassInstance.java | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'st/ClassInstance.java') diff --git a/st/ClassInstance.java b/st/ClassInstance.java index d51446f..804b1b0 100644 --- a/st/ClassInstance.java +++ b/st/ClassInstance.java @@ -29,13 +29,9 @@ public class ClassInstance extends AbstractInstance { else return false; - if (o.getName().equals(this.getName())) { - MinimalLogger.info(String.format("Found extension end.")); - if (o.getExtend() != null && o.getExtend().equals(this.getExtend())) - throw new TypecheckException(String.format("Recursive extension on %s detected", - this.toString())); + if (o.getName().equals(this.getName())) return true; - } else + else MinimalLogger.info(String.format("I (%s) do not have the same name as %s... Checking if I extend...", this.getName(), o.getName())); @@ -53,6 +49,33 @@ public class ClassInstance extends AbstractInstance { return false; } + public void recursiveExtendFilter() { + ClassInstance ce = this.getExtend(); + if (ce != null) + this.findMyselfHelper(ce); + } + + public boolean findMyselfHelper(ClassInstance c) { + /** + * Returns true if there is a path through extensions that reaches + * the original class. Such a case is a type error. + */ + if (this.getName().equals(c.getName())) { + MinimalLogger.info(String.format("%s is part of an extension loop!", + this.getName())); + throw new TypecheckException(String.format("Recursive extension detected!")); + } + + if (c.getExtend() == null) { + MinimalLogger.info(String.format("Search ended at %s.", + c.getName())); + return false; + } + + ClassInstance ce = c.getExtend(); + return this.findMyselfHelper(ce); + } + public ClassInstance getExtend() { /** * Returns the parent class, or -- cgit v1.2.3