Skip to content

D32: an if/else arm naming a mut-receiver field moves it out silently (field blanked, no diagnostic) #1395

Closed

Description

@ehartford

§2.2 / D32 (STRICT): a field never moves out implicitly; the only vacate is an explicit move place.field. An if-expression arm evades the check and vacates the field:

type S { p: str }
impl S:
    mut fn f():
        let path = if self.p.len() > 0: self.p else: ""
        print(path)
fn main:
    var s = S { p: "abc" }
    s.f()
    print(f"after=[{s.p}]")

Installed compiler and stage2 from main: with check ok; run prints abc then after=[]. The plain let path = self.p in the same receiver does not vacate (prints after=[abc]). Expected: the D32 move-site error with its move / .clone() fix-its (or, if a view binding is the ruling for the arm too, no vacate) — never a silent blank.

Found in #1364 (#1350): Sema.record_displaced_fn used this shape on self.current_module_path; collect_fn_decl then resolved the displaced fn's parameter types with an empty module path, so the --no-std tier gate treated std's own fence(order: Order) as user code (error: Order requires std --> <embedded-std>/std/collections.w:330), located with a [dbg] print of current_module_path at Sema.w require_std_tier_for_symbol ("" ) after collect_declarations set it to collections.w. The same shape already sat in Sema.record_named_type_with_pub (a mut fn, blanking current_module_path mid type collection) and the embed_file check in SemaCheck.w; #1364 rewrites all three to with_str_clone_ref(self.current_module_path) as the workaround this issue removes the need for.

The match-arm form (match c: true => self.p ...) should be checked in the same fix.

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