Repository navigation
sema: D143 holds for methods: self.m(…) and Owner.m(…) are self-calls - #2794
Merged
Merged
Conversation
…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.
Contributor
Author
|
Seed-driven battery GREEN on the stack top ba1cf73 ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.