Skip to content

ownership: E250 for a dropped owning struct, migrate Persian magazine and docs examples - #3672

Merged
BaseMax merged 3 commits into
mainfrom
fix/ownership-final
Nov 19, 2026
Merged

BaseMax merged 3 commits into
mainfrom
fix/ownership-final

Conversation

@BaseMax

@BaseMax BaseMax commented Nov 19, 2026 •

Copy link
Copy Markdown
Member
  • E250 now also rejects a bare statement that calls a user function whose returned struct owns a fresh string (ask() on its own). Nothing holds the result, so the string leaks the same way as for a local that is never freed. English and Persian messages, one error test per language, and a row in the ownership doc.
  • The Persian magazine posts still used ==, !=, <, > and friends in their code, which Persian mode has rejected since enforce comparison operator style by language #3352. A block-aware migration (only salam blocks that contain Persian code, plus inline examples that name a keyword) updates 36 posts. website/check-blog-code.sh on the Persian posts goes from 75 passing blocks to 128.
  • The Persian examples in SKILL.md and docs/design/THROW.md use the word operators too, and SKILL.md says "site" where textlint wanted it.

Checked on a build of this branch: the compiler's own source has no new hits, errors is 773 passed with the same six failures that also fail on 0.6.16, and the new error tests pass in both languages.

Not covered: 7 blog blocks still fail for other reasons (names with spaces in English-mode examples that E234 rejects, a post page value, an export that no longer exists). The Persian books under books/ are out of date and were left alone, and Vector<str> elements are still not checked.

Summary by CodeRabbit

  • New Features
    • The compiler now warns when a discarded function result contains a heap-allocated string that may not be freed. The diagnostic suggests retaining the result and freeing the string field or returning it.
  • Documentation
    • Updated Persian examples to use Salam’s word-based comparison syntax and clarified the error-handling mapping and ownership guidance.

Calling a user function whose struct result owns a fresh string, with nothing holding the result, leaks that string the same way an unfreed local does. English and Persian messages and tests.
…perators

Also says site instead of website on the style reference line, which textlint flagged.
Migrates the salam blocks and the inline examples in 36 posts. The blog code check goes from 75 of 135 blocks passing to 128 passing.
@BaseMax
BaseMax requested a review from a team as a code owner November 19, 2026 11:14
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The compiler now reports E250 when a discarded call result owns a heap string. Persian examples across the skill guide, design documentation, and blog posts now use word-form operators. The source-concept mapping table lists throw, try, and catch for error mapping.

Changes: Discarded struct ownership diagnostic

Layer / File(s) Summary
Detect and report dropped struct results
compiler/semantic/sema_strfree.salam, compiler/i18n.salam, tests/*/errors/own_struct_dropped.salam, docs/design/OWNERSHIP.md
Semantic analysis reports E250 when a discarded call result owns heap-string fields. English and Persian diagnostic messages, error tests, and ownership documentation cover this case.

Persian syntax documentation

Layer / File(s) Summary
Skill guide mappings and examples
SKILL.md
The source-concept mapping table lists throw, try, and catch for error mapping. Persian code examples use word-form comparison operators.
Persian design and blog examples
docs/design/THROW.md, website/content/fa/blog/*.md
Persian code examples replace symbolic operators with Salam’s word-form operators. The examples retain their described conditions and control flow.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Suggested reviewers: jbampton

Merge Risk: Low · up to fcbdd

The new E250 diagnostic can miss some dropped heap-string results when a function's return branches own different fields. Two Persian blog paragraphs still describe the old symbolic operators next to examples that now use word operators. Neither issue breaks existing behavior, and both are small, localized fixes.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown
Contributor
sha=fcbddae1d7c3d1d558df66d892b22a33c9109b3a

🤖 Salam AI review

Verdict: ⚠️ Review could not be parsed

commit fcbddae · 43 files · +223 −146 · model salam

Maximum steps for this agent have been reached. Below is a summary based on the diff and the files I was able to inspect.

Summary of review

The pull request makes three kinds of changes: (1) a compiler ownership check (E250) that now also rejects a bare statement calling a user function whose returned struct owns a fresh heap string, with English/Persian messages, two error tests, and an OWNERSHIP.md note; (2) a migration of Persian blog posts to word comparison operators; and (3) small SKILL.md/THROW.md doc fixes.

What I verified

  • The new sf_report_dropped_structs in compiler/semantic/sema_strfree.salam follows the existing pattern of sf_report_owned_structs: it guards with pkg_in_stdlib, collects AST_EXPR_STMT nodes, checks the expression is an AST_CALL whose type is not str, and reuses su_own_fields_expr to decide whether the returned struct owns a string. It is wired into SemaAutoFreeStrings alongside the other reporters, and is a private (non-pub) function placed before the public entry point, matching the file-order rule.
  • The two added error tests (tests/en/errors/own_struct_dropped.salam, tests/fa/errors/own_struct_dropped.salam) use the expected // EXPECT: E250 / // انتظار: خطا۲۵۰ forms and the Persian file starts with // زبان: فارسی.
  • OWNERSHIP.md gains the matching sentence about a bare call being rejected the same way.
  • The blog migration consistently replaces ==, !=, <, >, <=, >= with their Persian word forms (برابر, نابرابر, کوچکتر, بزرگتر, کوچکتربرابر, بزرگتربرابر) inside code blocks, and also updates prose examples that quoted operators.

Remaining concerns / not verified

  • I could not inspect compiler/i18n.salam (over size budget) or the full SKILL.md diff, so I could not confirm the exact English/Persian message strings or the "site" textlint fix; I rely on the author's statement that the new tests pass.
  • The compiler source and test harness are not present in this checkout, so I could not run salam_check or the error tests; the claim of "773 passed, same six failures" is taken on trust.
  • Seven blog blocks are acknowledged as still failing for unrelated reasons; that is acceptable for a partial migration but should be tracked.
  • Vector<str> elements are still not checked, as the PR notes.

Decision: merge. The change is focused, follows the project's conventions, and the new behaviour is covered by tests in both languages. The remaining items are explicitly out of scope.


⚠️ This review was written automatically by an AI and may contain mistakes. It is a helper for maintainers, not a replacement for a human review: check the code yourself before merging.

@BaseMax
BaseMax merged commit 1f8a046 into main Nov 19, 2026
13 of 14 checks passed
@BaseMax
BaseMax deleted the fix/ownership-final branch November 19, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant