Skip to content

Commit 1eda6e7

Browse files
Fix: accept Opaque-with-implementation in assertTransparent test (#1047)
PR #754 unified translateFunction and translateMethod, which applies return type constraints to class methods. This makes method bodies Opaque (with postconditions and implementation) instead of Transparent. The Opaque body with an implementation is semantically correct — the verifier can still reason about the body AND enforce the return type constraint. The test's assertTransparent was overly strict, rejecting Opaque bodies even when an implementation was present. Fix: accept both Transparent and Opaque-with-implementation in assertTransparent, since both provide the body for verification. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. --------- Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
1 parent 39d9622 commit 1eda6e7

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ jobs:
307307
sudo cp z3-4.13.4-x64-glibc-2.35/bin/z3 /usr/local/bin/
308308
fi
309309
- name: Run PySpec and dispatch tests
310-
run: PYTHON=python lake test -- Languages.Python --exclude Languages.Python.VerifyPythonTest
310+
run: PYTHON=python lake test -- Languages.Python
311311
- name: Run test script
312312
run: FAIL_FAST=1 ./scripts/run_cpython_tests.sh ${{ matrix.python_version }}
313313
working-directory: Tools/Python

StrataTestExtra/Languages/Python/VerifyPythonTest.lean

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ def toLaurel (pythonCmd : System.FilePath) (program : String)
2727
let laurel ← processPythonToLaurel pythonCmd (stringInputContext "test.py" program)
2828
pure (laurel, toString (Laurel.formatProgram laurel))
2929

30-
/-- Assert that a procedure with the given name exists and has a Transparent body. -/
31-
def assertTransparent (laurel : Laurel.Program) (procName : String) : IO Unit := do
30+
/-- Assert that a procedure has an implementation body available for verification
31+
(either Transparent or Opaque with an implementation). -/
32+
def assertHasBody (laurel : Laurel.Program) (procName : String) : IO Unit := do
3233
match laurel.staticProcedures.find? (fun p => p.name.text == procName) with
3334
| none => throw <| .userError s!"{procName} procedure not found in Laurel output"
3435
| some proc =>
3536
match proc.body with
3637
| .Transparent _ => pure ()
37-
| _ => throw <| .userError s!"{procName} body should be Transparent, not Opaque"
38+
| .Opaque _ (some _) _ => pure ()
39+
| _ => throw <| .userError s!"{procName} has no implementation body (External or Opaque without implementation)"
3840

3941
/-- Assert that a procedure with the given name exists and has an Opaque body. -/
4042
def assertOpaque (laurel : Laurel.Program) (procName : String) : IO Unit := do
@@ -240,7 +242,7 @@ def create_service() -> Any:
240242
-- Verifies that dispatch detection in __init__ doesn't break
241243
-- normal class translation.
242244
#guard_msgs (drop info) in
243-
#eval withPython (warnOnSkip := false) fun pythonCmd => do
245+
#eval withPython fun pythonCmd => do
244246
let program :=
245247
"class Wrapper:
246248
name: str
@@ -260,7 +262,7 @@ def main() -> None:
260262
-- Verifies that field method calls on user-defined classes don't cause
261263
-- "Coercion to Any not supported" or other translation errors.
262264
#guard_msgs (drop info) in
263-
#eval withPython (warnOnSkip := false) fun pythonCmd => do
265+
#eval withPython fun pythonCmd => do
264266
let program :=
265267
"class Svc:
266268
name: str
@@ -292,7 +294,7 @@ def main() -> None:
292294
-- Dispatch detection inside try/except in __init__.
293295
-- self.svc = Svc() inside a try block should still be detected.
294296
#guard_msgs (drop info) in
295-
#eval withPython (warnOnSkip := false) fun pythonCmd => do
297+
#eval withPython fun pythonCmd => do
296298
let program :=
297299
"class Svc:
298300
name: str
@@ -338,7 +340,7 @@ def main() -> None:
338340
"
339341
let (laurel, output) ← toLaurel pythonCmd program
340342
let calcAdd := manglePythonMethod "Calculator" "add"
341-
assertTransparent laurel calcAdd
343+
assertHasBody laurel calcAdd
342344
unless containsSubstr output s!"{calcAdd}(" do
343345
throw <| IO.userError s!"Expected '{calcAdd}(' in Laurel output but not found"
344346

@@ -660,7 +662,7 @@ def retry(func: typing.Callable[..., typing.Any], retries: int = 3) -> typing.An
660662
-- is correctly resolved and inlined. If the method were unresolved (Hole),
661663
-- the result would be havocked and the assertion would be unknown/failing.
662664
#guard_msgs in
663-
#eval withPython (warnOnSkip := false) fun pythonCmd => do
665+
#eval withPython fun pythonCmd => do
664666
let program :=
665667
"class Calculator:
666668
def __init__(self, base: int) -> None:
@@ -685,7 +687,7 @@ def main() -> None:
685687
-- Inner.greet's body must be resolved through the Outer.inner field
686688
-- for the assertion to be verifiable.
687689
#guard_msgs in
688-
#eval withPython (warnOnSkip := false) fun pythonCmd => do
690+
#eval withPython fun pythonCmd => do
689691
let program :=
690692
"class Inner:
691693
def __init__(self, prefix: str) -> None:

0 commit comments

Comments
 (0)