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

[View types] lent parameter can cause a segfault #17621

Closed
konsumlamm opened this issue Apr 2, 2021 · 0 comments · Fixed by #17628
Closed

[View types] lent parameter can cause a segfault #17621

konsumlamm opened this issue Apr 2, 2021 · 0 comments · Fixed by #17628
Assignees

Comments

@konsumlamm
Copy link
Contributor

Example

{.experimental: "views".}

type Test = ref object
  foo: int

proc modify(self: lent Test) =
  self.foo += 1

let test = Test(foo: 12)
modify(test)

Current Output

SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)

Expected Output

A compiler error. Either something like

Error: invalid type: 'lent Test' in this context: 'proc (self: lent Test)' for proc

(which is what happens without {.experimental: "views".}, based on #16898 (comment)) or an error because self is modified through a lent.

Possible Solution

  • Disallow lent for parameters.

Additional Information

Related issue: #16898.
I decided to open a new issue for this, since this causes a segfault instead of invalid codegen, but the underlying issue seems to be the same.

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-04-02
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 9abd383
active boot switches: -d:release

@ringabout ringabout self-assigned this Apr 3, 2021
ringabout added a commit to ringabout/Nim that referenced this issue Apr 3, 2021
ringabout added a commit to ringabout/Nim that referenced this issue Apr 3, 2021
Araq pushed a commit that referenced this issue Apr 6, 2021
* fix #16898
* fix #17621

* Update compiler/semtypes.nim
PMunch pushed a commit to PMunch/Nim that referenced this issue Mar 28, 2022
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

Successfully merging a pull request may close this issue.

2 participants