Skip to content

Sema: a consuming str parameter of an associated call (T.make(p)) escapes the use-after-move check; a free call is diagnosed #1588

Closed

Description

@ehartford

Repro

type T { n: i64 }
fn T.make(s: str) -> T: T { n: s.len() }
fn free_make(s: str) -> T: T { n: s.len() }
fn main:
    let p = "abc"
    let t = T.make(p)
    print(f"assoc: [{p}] {t.n}")
    let q = "abc"
    let u = free_make(q)
    print(f"free: [{q}] {u.n}")

Expected

Both prints are "use of moved value" errors (§3.8: a plain T parameter consumes; p and q are moved into the call).

Actual

Only the free call is diagnosed ({q} at line 10). The associated call T.make(p) moves p and the later {p} compiles; at run time it prints an empty string (the moved-from str). Same program with the facade-rendered CFile.fopen(path, "r") and print(path) afterwards: compiles, prints path empty.

Found while implementing modeled C stage 7 (the rendered constructors' str parameters are becoming &str, which sidesteps this for facades; the checker hole is independent).

Route

Move-checker drift (:move-audit class): the associated-function call path does not run the consuming-parameter transfer at the call site the way the free-call path does.

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