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

lent pointer outlives origin for global/threadvar #24624

Open
nitely opened this issue Jan 19, 2025 · 1 comment
Open

lent pointer outlives origin for global/threadvar #24624

nitely opened this issue Jan 19, 2025 · 1 comment

Comments

@nitely
Copy link
Contributor

nitely commented Jan 19, 2025

Description

This compiles even though the returned lent pointer outlives the threadvar value. Same for globals. Try -d:useMalloc for a random output.

type Foo = ref object
  x: seq[int]

var foo {.threadvar.}: seq[Foo]

proc genfoo(): lent Foo =
  foo = @[Foo(x: @[1,2,3])]
  return foo[0]

proc echoFoo() =
  var x = genfoo()
  foo[0] = nil
  foo.setLen 0
  echo x[].x
  echo x[].x.len
echoFoo()

Nim Version

Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2025-01-18
Copyright (c) 2006-2025 by Andreas Rumpf

git hash: 2af9ddc
active boot switches: -d:release

Current Output

@[1, 2, 3]
23859

Expected Output

Compilation error (or it should copy in this case?).

Known Workarounds

No response

Additional Information

No response

@nitely
Copy link
Contributor Author

nitely commented Jan 19, 2025

it also occurs when returning var Foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant