Skip to content

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

Closed
@treeform

Description

@treeform

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions