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

@[heap] flag in wrapper struct does not make the error disappear #21500

Closed
lv37 opened this issue May 14, 2024 · 0 comments · Fixed by #21511
Closed

@[heap] flag in wrapper struct does not make the error disappear #21500

lv37 opened this issue May 14, 2024 · 0 comments · Fixed by #21511
Assignees
Labels
Bug This tag is applied to issues which reports bugs. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@lv37
Copy link
Contributor

lv37 commented May 14, 2024

Describe the bug

module main

@[heap]
struct Wrapper {
    a &int = unsafe { nil }
}

fn test[T](a &T) Wrapper {
    $if T is int {
        return Wrapper{a}
    }
    return Wrapper{}
}

fn main() {
    a := 123
    println(test(a).a)
}

Reproduction Steps

Compile the above code.

Expected Behavior

Compile successfully.

Current Behavior

main.v:10:24: error: `a` cannot be assigned outside `unsafe` blocks as it might refer to an object stored on stack. Consider wrapping the `T` object in a `struct` declared as `[heap]`.
    8 | fn test[T](a &T) Wrapper {
    9 |     $if T is int {
   10 |         return Wrapper{a}
      |                        ^
   11 |     }
   12 |     return Wrapper{}

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.5 58a8fc6

Environment details (OS name and version, etc.)

V full version: V 0.4.5 b347f54.58a8fc6
OS: linux, Linux version 6.8.9-300.fc40.x86_64 (mockbuild@5f5c14101bdf4cb8942130379360ff7d) (gcc (GCC) 14.0.1 20240411 (Red Hat 14.0.1-0), GNU ld version 2.41-34.fc40) #1 SMP PREEMPT_DYNAMIC Thu May  2 18:59:06 UTC 2024
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz

getwd: /home/user/Projects/learncpp
vexe: /home/user/.local/lib/v/v
vexe mtime: 2024-05-13 20:51:27

vroot: OK, value: /home/user/.local/lib/v
VMODULES: OK, value: /home/user/.vmodules
VTMP: OK, value: /tmp/v_1002

Git version: git version 2.45.0
Git vroot status: weekly.2024.14-312-g58a8fc6c
.git/config present: true

CC version: cc (GCC) 14.1.1 20240507 (Red Hat 14.1.1-1)
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

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.

@lv37 lv37 added the Bug This tag is applied to issues which reports bugs. label May 14, 2024
@felipensp felipensp added the Unit: Checker Bugs/feature requests, that are related to the type checker. label May 14, 2024
@felipensp felipensp self-assigned this May 15, 2024
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: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants