summaryrefslogtreecommitdiff
path: root/st/ClassInstance.java
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-05-12 19:26:57 -0600
committerbd-912 <bdunahu@colostate.edu>2024-05-12 19:26:57 -0600
commit297d7292bf8b42eda443ad65b618a697f7ef67ad (patch)
tree60af6fa3a5171332d70c3051d5c097d22e4d7675 /st/ClassInstance.java
parente5709fbc956d3395e7b401fd5198524e02542e81 (diff)
Unconfirmed fix for recursive-extension finderHEADmaster
Diffstat (limited to 'st/ClassInstance.java')
-rw-r--r--st/ClassInstance.java35
1 files changed, 29 insertions, 6 deletions
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