Skip to content

Commit 918c3e3

Browse files
aallanclaude
andcommitted
aver: handle ] followed by trailing comment in module-effects strip
Both `stripped.endswith("]")` checks in _strip_module_effects were brittle to Aver's trailing line comments (`// ...`). For an LLM-emitted declaration like: effects [Console.print] // pure module the strip pass would: 1. match the opener regex (correctly) 2. fail `endswith("]")` because the line ends in `e` (`pure`) 3. enter `skip_until_close` mode 4. chew through subsequent lines until something happens to end in `]` — likely catastrophic for the function body Same hazard on the closing line of a multi-line list: effects [ Console.print, ] // pure module Replace both `endswith("]")` checks with `"]" in stripped`. Module-level effect lists are simple identifier sequences with no string literals or nested brackets, so the theoretical false-match concern (a `]` inside a string in the list) doesn't apply now or in any planned Aver evolution. Tests: - `test_strips_inline_effects_with_trailing_comment` — the inline variant; asserts the function body is intact (i.e. NOT eaten by a runaway skip_until_close). - `test_strips_multiline_effects_with_trailing_comment_on_close` — same hazard on the closing line of a multi-line list. Both new tests pass; full `tests/test_runner.py` suite green (106 passed locally). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 661a0b7 commit 918c3e3

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

tests/test_runner.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,50 @@ def test_only_strips_inside_module_header(self):
986986
# Header `effects` line gone, fn-body `effects` line kept.
987987
assert sum(1 for line in lines if "effects [Console.print]" in line) == 1
988988

989+
def test_strips_inline_effects_with_trailing_comment(self):
990+
# Aver allows `// ...` line comments; an inline `effects
991+
# [...] // comment` declaration must be detected as
992+
# single-line, not fall into the multi-line skip path that
993+
# would chew through the function body.
994+
code = (
995+
"module M\n"
996+
' intent = "t"\n'
997+
" effects [Console.print] // pure module\n"
998+
"\n"
999+
"fn f() -> Unit\n"
1000+
" ! [Console.print]\n"
1001+
' Console.print("hi")\n'
1002+
)
1003+
result = _strip_module_effects(code)
1004+
# Header `effects` line is gone.
1005+
assert "effects [Console.print]" not in result
1006+
# And critically: the function body is intact, NOT eaten by
1007+
# a runaway skip_until_close.
1008+
assert "fn f() -> Unit" in result
1009+
assert 'Console.print("hi")' in result
1010+
1011+
def test_strips_multiline_effects_with_trailing_comment_on_close(self):
1012+
# Same hazard on the closing line of a multi-line list:
1013+
# `]` can be followed by a trailing comment.
1014+
code = (
1015+
"module M\n"
1016+
' intent = "t"\n'
1017+
" effects [\n"
1018+
" Console.print,\n"
1019+
" ] // pure module\n"
1020+
"\n"
1021+
"fn f() -> Unit\n"
1022+
" ! [Console.print]\n"
1023+
' Console.print("hi")\n'
1024+
)
1025+
result = _strip_module_effects(code)
1026+
# Whole effects block gone (header through close).
1027+
assert "effects [" not in result
1028+
assert "Console.print," not in result
1029+
# Function body intact.
1030+
assert "fn f() -> Unit" in result
1031+
assert 'Console.print("hi")' in result
1032+
9891033

9901034
class TestEvaluateAverCode:
9911035
def _sample_problem(self, test_cases=None):

vera_bench/runner.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,11 @@ def _strip_module_effects(code: str) -> str:
596596

597597
if skip_until_close:
598598
# Multi-line `effects [\n ...\n]` — drop everything up to
599-
# and including the line that closes the bracket.
600-
if stripped.endswith("]"):
599+
# and including the line that closes the bracket. Use
600+
# presence rather than `endswith("]")` so a trailing line
601+
# comment (Aver's `// ...` syntax) doesn't make us miss
602+
# the close and chew through the rest of the file.
603+
if "]" in stripped:
601604
skip_until_close = False
602605
continue
603606

@@ -622,7 +625,11 @@ def _strip_module_effects(code: str) -> str:
622625
and indent_len > 0
623626
and _AVER_EFFECTS_OPEN_RE.match(stripped)
624627
):
625-
if stripped.endswith("]"):
628+
# Same `]`-presence rule as the skip_until_close branch —
629+
# tolerates `effects [...] // pure module` (single-line
630+
# declaration with a trailing comment) without falling into
631+
# the multi-line skip path that would eat the function body.
632+
if "]" in stripped:
626633
continue
627634
skip_until_close = True
628635
continue

0 commit comments

Comments
 (0)