Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free an optional structure #22042

Closed
esquerbatua opened this issue Aug 13, 2024 · 7 comments · Fixed by #22060
Closed

Free an optional structure #22042

esquerbatua opened this issue Aug 13, 2024 · 7 comments · Fixed by #22060
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@esquerbatua
Copy link
Contributor

esquerbatua commented Aug 13, 2024

Describe the bug

Try to free an structure with a optional field

Reproduction Steps

module main

pub struct Opt {
    test ?Test
}

pub struct Test {
    a string
    b string @[skip]
}

fn main() {
    t := Opt{
        test: Test{
            a: "a",
            b: "b"
        }
    }

    println("t: ${t}")

    defer {
        unsafe {
            t.free()
        }
    }
}

Expected Behavior

The program compile and run correctly without errors

Current Behavior

======== Output of the C Compiler (cc) ========
/tmp/v_1000/jsonx.tmp.c: In function ‘_option_main__Test_free’:
/tmp/v_1000/jsonx.tmp.c:2254:25: error: ‘_option_main__Test’ has no member named ‘a’
 2254 |         string_free(&(it->a));
      |                         ^~
/tmp/v_1000/jsonx.tmp.c:2255:25: error: ‘_option_main__Test’ has no member named ‘b’
 2255 |         string_free(&(it->b));
      |                         ^~
/tmp/v_1000/jsonx.tmp.c: In function ‘main__main’:
/tmp/v_1000/jsonx.tmp.c:13351:24: error: incompatible type for argument 1 of ‘main__Opt_free’
13351 |         main__Opt_free(t);
      |                        ^
      |                        |
      |                        main__Opt
/tmp/v_1000/jsonx.tmp.c:2258:33: note: expected ‘main__Opt *’ but argument is of type ‘main__Opt’
 2258 |  void main__Opt_free(main__Opt* it) {
      |                      ~~~~~~~~~~~^~
===============================================

Possible Solution

No response

Additional Information/Context

No response

V version

Current V version: V 0.4.7 e16d727, timestamp: 2024-08-12 16:08:24 +0300

Environment details (OS name and version, etc.)

V full version: V 0.4.7 a7db095.e16d727
OS: linux, Ubuntu 24.04 LTS
Processor: 16 cpus, 64bit, little endian, AMD Ryzen 7 7840HS w/ Radeon 780M Graphics

vexe: /home/esquerbatua/git/v/v
vexe mtime: 2024-08-13 09:12:41

vroot: OK, value: /home/esquerbatua/git/v
VMODULES: OK, value: /home/esquerbatua/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.43.0
Git vroot status: weekly.2024.32-32-ge16d727d
.git/config present: true

CC version: cc (Ubuntu 13.2.0-23ubuntu4) 13.2.0
thirdparty/tcc status: thirdparty-linux-amd64 a0799a5b

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@esquerbatua esquerbatua added the Bug This tag is applied to issues which reports bugs. label Aug 13, 2024
@felipensp
Copy link
Member

felipensp commented Aug 16, 2024

This must be a checker error, right @spytheman @medvednikov ? (Because Opt is not a ptr type).

@felipensp felipensp added the Unit: Checker Bugs/feature requests, that are related to the type checker. label Aug 16, 2024
@StunxFS
Copy link
Contributor

StunxFS commented Aug 16, 2024

@felipensp

This must be a checker error, right @spytheman @medvednikov ? (Because Opt is not a ptr type).

But Opt may contain fields that require a call to .free() to free memory

@felipensp
Copy link
Member

@felipensp

This must be a checker error, right @spytheman @medvednikov ? (Because Opt is not a ptr type).

But Opt may contain fields that require a call to .free() to free memory

Makes sense. In this case this feature requires more work than was reported.

@felipensp felipensp self-assigned this Aug 16, 2024
@felipensp felipensp added Unit: cgen Bugs/feature requests, that are related to the default C generating backend. and removed Unit: Checker Bugs/feature requests, that are related to the type checker. labels Aug 16, 2024
@esquerbatua
Copy link
Contributor Author

ty!

@esquerbatua
Copy link
Contributor Author

Sorry @felipensp, it still failing with this example:

module main

pub struct Opt {
    test ?Test
}

pub struct Test {
    b ?string
}

fn main() {
    t := Opt{
        test: Test{
            b: "b"
        }
    }

    println("t: ${t}")

    defer {
        unsafe {
            t.free()
        }
    }
}

@spytheman
Copy link
Member

Please open another issue @esquerbatua . The PR solved this one.

@esquerbatua
Copy link
Contributor Author

@spytheman ty! created: #22068

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants