Skip to content

sema: D143 holds for methods: self.m(…) and Owner.m(…) are self-calls - #2794

Merged
ehartford merged 1 commit into
fix-809-root-spellingfrom
fix-d143-methods
Oct 29, 2026
Merged

ehartford merged 1 commit into
fix-809-root-spellingfrom
fix-d143-methods

Conversation

@ehartford

@ehartford ehartford commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

A recursive method with no return type was silently typed Unit (free functions inferred, D143). See the commit message for the lldb-located cause. Gate green. Draft until the stack's battery is green.

…wner.m(…) are self-calls (#2520)

A method with no return type that calls itself was silently typed Unit:
`fn depth(n: i32): if n <= 0: return 0 … 1 + self.depth(n - 1)` gave
"operand of `+` is Unit", and a caller read "has type Unit". A free
function of the same shape infers (D143).

Root cause (lldb on stage1, Sema.body_calls_itself and
check_fn_body_with_sig_at over the repro): the method's body reached
body_calls_itself, which matched only a bare `NK_IDENT` callee against the
declaration's parsed name. A method's parsed name is `Owner.m` and its
self-call is a field access (`self.m`, `Owner.m`, `Self.m`), so it
returned false, the body took one pass, and the self-call read the
signature's placeholder Unit. A `pub` recursive method also escaped Law 6's
"declares its return type".

- body_calls_itself recognizes `self.m(…)`, `Self.m(…)` and `Owner.m(…)`
  for a declaration parsed `Owner.m` (an impl method or `fn Owner.m`);
  decl_call_name is the one place that strips `Owner.`, shared with
  prepare_body_order.
- The first pass's open result is the signature's: its return type is
  `Never` until the pass decides, so a free call and a method call read it
  alike. The free-call site's own `fn_sym == recursion_open_sym` test, and
  recursion_self_calls (written, never read), are gone.

Tests: behav_d143_method_calls_itself (instance and type-function
self-calls) and err_d143_pub_method_recursive_declares fail on the
installed compiler and pass on stage1; the D143 suite passes.
@ehartford
ehartford added this pull request to stack #2797 October 28, 2026 23:18
@ehartford ehartford changed the title fix d143 methods sema: D143 holds for methods: self.m(…) and Owner.m(…) are self-calls Oct 28, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Seed-driven battery GREEN on the stack top ba1cf73 (with run tools/battery.w: gate, uat, battery-checks).

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