Skip to content

Commit 40b890d

Browse files
don't allow names to be redefined
1 parent 66f92f0 commit 40b890d

File tree

1 file changed

+5
-1
lines changed
  • types/src/main/java/com/compilerprogramming/ezlang/types

1 file changed

+5
-1
lines changed

types/src/main/java/com/compilerprogramming/ezlang/types/Scope.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.compilerprogramming.ezlang.types;
22

3+
import com.compilerprogramming.ezlang.exceptions.CompilerException;
4+
35
import java.util.ArrayList;
46
import java.util.LinkedHashMap;
57
import java.util.List;
@@ -27,7 +29,7 @@ public Scope(Scope parent) {
2729
}
2830

2931
public Symbol lookup(String name) {
30-
Symbol symbol = bindings.get(name);
32+
Symbol symbol = localLookup(name);
3133
if (symbol == null && parent != null)
3234
symbol = parent.lookup(name);
3335
return symbol;
@@ -38,6 +40,8 @@ public Symbol localLookup(String name) {
3840
}
3941

4042
public Symbol install(String name, Symbol symbol) {
43+
if (localLookup(name) != null)
44+
throw new CompilerException("Symbol " + name + " already defined in scope");
4145
bindings.put(name, symbol);
4246
return symbol;
4347
}

0 commit comments

Comments
 (0)