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

New JS mdoe issue: return + ref ints. #21317

Closed
treeform opened this issue Jan 30, 2023 · 2 comments · Fixed by #21320
Closed

New JS mdoe issue: return + ref ints. #21317

treeform opened this issue Jan 30, 2023 · 2 comments · Fixed by #21320

Comments

@treeform
Copy link
Contributor

Description

This used to work and is a recent breakage. Jsony tests cough this: https://github.com/treeform/jsony/

Tiny code example to reproduce:

proc parseHook*(v: var ref int) =
  var a: ref int
  new(a)
  a[] = 123
  v = a

proc fromJson2*(): ref int =
  parseHook(result)

echo fromJson2()[]

Nim Version

Nim Compiler Version 1.6.10 [Linux: amd64]
Compiled at 2022-11-21
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: f151925
active boot switches: -d:release

Current Output

/home/me/p/try/jsrefint.js:675
rawEcho(HEX24_318767107((Temporary1 = fromJson2_436207632(), Temporary1)[0][Temporary1[1]]));
                                                                           ^

TypeError: Cannot read property 'undefined' of undefined
    at Object.<anonymous> (/home/me/p/try/jsrefint.js:675:76)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47
Error: execution of an external program failed: '/usr/bin/node --unhandled-rejections=strict /home/me/p/try/jsrefint.js '

Expected Output

123

Possible Solution

If you don't use return, but call it some other way it works:

proc parseHook*(v: var ref int) =
  var a: ref int
  new(a)
  a[] = 123
  v = a

var
  b: ref int
parseHook(b)

or don't use ref int

proc parseHook*(v: var int) =
  v = 123

proc fromJson2*(): int =
  parseHook(result)

echo fromJson2()

also works.

Its only when ref int + result there is an issue.

Additional Information

This works with C backed no issues.

@ringabout
Copy link
Member

Works in 1.6.2

@ringabout
Copy link
Member

caused by #19393

Araq pushed a commit that referenced this issue Feb 1, 2023
…rs [backport 1.6] (#21320)

fixes #21317; regression; etyBaseIndex should return fat pointers
narimiran pushed a commit that referenced this issue Feb 14, 2023
…rs [backport 1.6] (#21320)

fixes #21317; regression; etyBaseIndex should return fat pointers

(cherry picked from commit cbf3ed9)
survivorm pushed a commit to survivorm/Nim that referenced this issue Feb 28, 2023
…t pointers [backport 1.6] (nim-lang#21320)

fixes nim-lang#21317; regression; etyBaseIndex should return fat pointers
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
…t pointers [backport 1.6] (nim-lang#21320)

fixes nim-lang#21317; regression; etyBaseIndex should return fat pointers
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
…t pointers [backport 1.6] (nim-lang#21320)

fixes nim-lang#21317; regression; etyBaseIndex should return fat pointers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants