Skip to content

Commit 6706ba0

Browse files
committed
fix bug: let, letrec should require unique binding names in the same let/letrec
1 parent 538997a commit 6706ba0

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

unpythonic/let.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ def _let(mode, body, **bindings):
246246
# are then already bound when the wrappers are called.
247247
env = _envcls()
248248
for k, v in bindings.items():
249+
if k in env:
250+
raise AttributeError("Cannot rebind the same name '{}' in a {} initializer list".format(k, mode))
249251
if mode == "letrec" and callable(v):
250252
try:
251253
if not arity_includes(v, 1):

unpythonic/lispylet.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ def _let(bindings, body, *, env=None, mode="let"):
238238
return env if body is None else body(env)
239239

240240
(k, v), *more = bindings
241+
if k in env:
242+
raise AttributeError("Cannot rebind the same name '{}' in a {} initializer list".format(k, mode))
241243
if mode == "letrec" and callable(v):
242244
try:
243245
if not arity_includes(v, 1):

0 commit comments

Comments
 (0)