bugfix for duplicate formal params

main
Sandy Brownlee 2 years ago
parent 82a5535d19
commit 4be8f47351
  1. 10
      Triangle.Compiler/src/main/java/triangle/contextualAnalyzer/IdentificationTable.java

@ -53,7 +53,7 @@ public final class IdentificationTable {
// same identifier at the current level. // same identifier at the current level.
public void enter(String id, Declaration attr) { 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); 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. // otherwise returns the attribute field of the entry found.
public Declaration retrieve(String id) { 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; var entry = this.latest;
while (true) { while (true) {
if (entry == null) { if (entry == null || (thisLevelOnly && entry.level < this.level)) {
break; break;
} else if (entry.id.equals(id)) { } else if (entry.id.equals(id)) {
return entry.attr; return entry.attr;