Skip to content

Commit

Permalink
Merge pull request #281 from OpShin/fix/enforce_forbidden_overwrite
Browse files Browse the repository at this point in the history
Add a test case for forbidden overwrites
  • Loading branch information
nielstron authored Oct 29, 2023
2 parents a29af3b + 1809115 commit b40b49a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion opshin/rewrite/rewrite_forbidden_overwrites.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RewriteForbiddenOverwrites(CompilingNodeTransformer):
step = "Checking for forbidden name overwrites"

def visit_Name(self, node: Name) -> Name:
if node.ctx == Store() and node.id in FORBIDDEN_NAMES:
if isinstance(node.ctx, Store) and node.id in FORBIDDEN_NAMES:
raise ForbiddenOverwriteError(
f"It is not allowed to overwrite name {node.id}"
)
Expand Down
11 changes: 11 additions & 0 deletions opshin/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2160,3 +2160,14 @@ def append_byte_string(x: bytes, y: bytes) -> bytes:
return x + y

assert append_byte_string(b"hello", b"world") == b"helloworld"

@unittest.expectedFailure
def test_forbidden_overwrite(self):
source_code = """
def validator(
d: int
):
PlutusData = d
return d
"""
builder._compile(source_code)

0 comments on commit b40b49a

Please sign in to comment.