From 4be8f473512074d7efa27cbe3766ebda12cc1bcc Mon Sep 17 00:00:00 2001 From: Sandy Brownlee Date: Wed, 31 Aug 2022 16:56:56 +0100 Subject: [PATCH] bugfix for duplicate formal params --- .../contextualAnalyzer/IdentificationTable.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/IdentificationTable.java b/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/IdentificationTable.java index 6e8eabb..33d1157 100644 --- a/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/IdentificationTable.java +++ b/Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/IdentificationTable.java @@ -53,7 +53,7 @@ public final class IdentificationTable { // same identifier at the current level. public void enter(String id, Declaration attr) { - attr.duplicated = retrieve(id) != null; + attr.duplicated = retrieve(id, true) != null; this.latest = new IdEntry(id, attr, this.level, this.latest); } @@ -64,9 +64,15 @@ public final class IdentificationTable { // otherwise returns the attribute field of the entry found. public Declaration retrieve(String id) { + return retrieve(id, false); + } + + // thisLevelOnly limits the search to only the current level + + public Declaration retrieve(String id, boolean thisLevelOnly) { var entry = this.latest; while (true) { - if (entry == null) { + if (entry == null || (thisLevelOnly && entry.level < this.level)) { break; } else if (entry.id.equals(id)) { return entry.attr;