Skip to content

An inherited default method's body is checked by the function-body check (#3360) - #3382

Merged
ehartford merged 1 commit into
mainfrom
default-body-one-check
Nov 16, 2026
Merged

ehartford merged 1 commit into
mainfrom
default-body-one-check

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #3360.

SemaCheck.check_trait_default_method_body_for_impl checked a default body with a smaller copy of the function-body check. The part of check_fn_body_with_sig_once that checks a body under its return demand is now one method, check_body_under_return, with two callers (D65: one owner): the tail's context (D43, §4.9a), the drops at the body's end (#1827), move-site liveness, and what the returned tail does (check_body_result: field moves, effects, view origins). begin_body_bindings replaces three copies of the same two lines.

What changes for programs:

  • a T tail under Option[T] in a default method is Some (was "the function returns Option[i32], this value is i32"): test/behavior/behav_3360_default_method_option_tail.w;
  • a default method that returns a view of a parameter it owns is refused, "returned view may outlive its origin 'xs'", as the same free function always was. The old check accepted it: test/compile_errors/err_3360_default_method_returns_view_of_owned_param.w.

Both tests fail before the change. The 68 existing tests with default in their name pass with the dev compiler.

Battery GREEN (3638d6e); :release-checks green.

…eck: check_body_under_return is the one owner of the tail's context, the drops at the body's end, move-site liveness and the returned tail (a T tail under Option[T] works; a returned view of an owned parameter is refused) (#3360)
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.

A default trait method's body is checked by a smaller copy of the function-body check: an implicit Ok tail is an ICE

1 participant