Skip to content

Commit

Permalink
Merge pull request #232 from OpShin/fix/correct_in_list_check
Browse files Browse the repository at this point in the history
Fix an error where UnionType was always allowed to be compared with List[X]
  • Loading branch information
nielstron authored Jul 27, 2023
2 parents efa28e8 + 829ee2a commit 2bef9c2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions opshin/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2298,3 +2298,19 @@ def validator(x: int) -> str:
code = compiler.compile(ast).compile()
res = uplc_eval(uplc.Apply(code, uplc.PlutusInteger(1)))
self.assertEqual(res.value, b"hello")

@unittest.expectedFailure
def test_in_list(self):
source_code = """
from opshin.prelude import *
def validator(
d: Nothing,
r: Nothing,
context: ScriptContext,
):
assert context.purpose in context.tx_info.signatories
"""
ast = compiler.parse(source_code)
code = compiler.compile(ast)
code = code.compile()
2 changes: 1 addition & 1 deletion opshin/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def cmp(self, op: cmpop, o: "Type") -> plt.AST:
if (
isinstance(o, ListType)
and isinstance(o.typ, InstanceType)
and (o.typ.typ >= t or t >= o.typ.typ for t in self.typs)
and any(o.typ.typ >= t or t >= o.typ.typ for t in self.typs)
):
if isinstance(op, In):
return plt.Lambda(
Expand Down

0 comments on commit 2bef9c2

Please sign in to comment.