Skip to content

checker accepts returned view of a consuming (plain-T) parameter — dangling view, runtime SEGV #718

Closed

Description

@ehartford

Repro (was test/behavior/behav_coerced_borrow_param_ok.w before its migration to &str):

type View ephemeral { s: &str }
fn f(src: str) -> View:
    View { s: src }
fn main:
    let s = "hi"
    let v = f(s)
    print(v.s ++ "!")

Compiles clean; the binary exits 139. Post-D5 (§3.8) a plain str parameter CONSUMES: src is dropped when f returns, so View { s: src } returns a view of a dying place. The escape checker misses it because view_origin_is_stack_local (src/SemaCheck.w:9263) returns 0 for every parameter — pre-D5 logic from when a read-only plain param was a borrow. A parameter is a non-dying origin only when its declared mode is &T (or another non-consuming mode); a consuming param is a dying local for view-origin purposes.

Expected: error: returned view may outlive its origin 'src' (same diagnostic the checker already emits for locals).

Note: the enforcement-side twin of the #714 family (declared mode is authoritative both for what callers must write and for what escapes).

Activity

  1. ehartford commented on Sep 1, 2026

    @ehartford
    ContributorAuthor

    Fixed: view_origin_is_stack_local now consults the DECLARED mode instead of exempting every parameter (the pre-D5 hole). A &T param and a fn/mut fn receiver borrow a caller place — non-dying origins, unchanged. A plain consuming T param and a move fn receiver die when the callee returns, so an escaping view of them is rejected with the same 'returned view may outlive its origin' diagnostic locals get. The repro errors at the View construction; move fn take_view() -> &str: &self.s errors too; the compiler self-checks clean under the stricter rule.

    Note for the record: behav_byvalue_view_escape_tail/nested pinned the RETIRED share-place reading of this exact shape ('by-value param is the caller's place; escaping views valid') and passed only by physical accident of the indirect ABI. Per the D5 supersession (declared signature authoritative; a plain consuming T is owned even when its ABI is indirect) both moved to compile_errors as negative fixtures. Full :test green, evidence recorded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions