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

SIGSEGV when returning and initializing Result in one statement when openArray and generics are involved #52

Open
etan-status opened this issue Jan 21, 2025 · 2 comments

Comments

@etan-status
Copy link
Contributor

import results

type X[flag: static bool] = object
  l: int

func init(
    T: typedesc[X],
    a: openArray[int]): Opt[X[false]] =
  ok X[false](l: a.len)

echo $X.init([1,3,3,7])
% nim -v
Nim Compiler Version 2.0.14 [MacOSX: arm64]
Compiled at 2025-01-06
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: bf4de6a394e040d9810cba8c69fb2829ff04dcc6
active boot switches: -d:release
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
zsh: segmentation fault  nim c -r test

It works fine when doing ok on a separate line:

import results

type X[flag: static bool] = object
  l: int

func init(
    T: typedesc[X],
    a: openArray[int]): Opt[X[false]] =
  let res = X[false](l: a.len)
  ok res

echo $X.init([1,3,3,7])

It also works fine when using std/options instead of results:

import std/options

type X[flag: static bool] = object
  l: int

func init(
    T: typedesc[X],
    a: openArray[int]): Option[X[false]] =
  some X[false](l: a.len)

echo $X.init([1,3,3,7])

It's broken on both refc and orc --mms.

@etan-status
Copy link
Contributor Author

Possibly related: https://github.com/etan-status/eth-light/blob/14565506b8f1ce45db140c162df85fa240d59842/UpdateWasm#L33

I needed the same fix to workaround some memory corruption in wasm.

Maybe a lent bug.

@etan-status
Copy link
Contributor Author

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