Skip to content

[BUG] Problem with move symantics after b24ce4d #230

@Burnett01

Description

@Burnett01

Describe the bug

Prior to commit b24ce4d the following code was valid:

struct Test
{
    a: String;
    b: int;
}

fn main() -> int {
    let x = String::from("Hello"); // heap

    let test: Test = Test{ a: x, b: 1 };  // stack
    x.forget();

    test.a.free();

    return 0;
}

At+after that commit the following error is emitted:

error: Use of moved value 'x'
  --> code.zc:16:5
   |
16 |     x.forget();
   |     ^ here
   |
   = help: This type owns resources and cannot be implicitly copied
   |
   = help: Consider using a reference ('&') to borrow the value instead

To Reproduce

Checkout the commit prior to b24ce4d

  1. git checkout 68525fd9fbbef05bd116505312d2d3ef5574960d

  2. make clean && make install

  3. zc run code.zc

= works

Checkout the commit after 68525fd

  1. git checkout b24ce4d7849cec02a9f336f2c1264e0d907bf0c9

or git checkout main

  1. make clean && make install

  2. zc run code.zc

= error

Expected behavior

It should work (unless I'm mistaken) since forget() is intended to make test.a the owner of x.

Screenshots
n/a

Environment (please complete the following information):

  • OS: Ubuntu 22.04.1
  • Zen C Version: latest
  • Compiler: GCC 13.3.0

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions