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

Default value of object parameterized with a RootRef generates incorrect C #20699

Closed
deech opened this issue Oct 29, 2022 · 3 comments
Closed

Comments

@deech
Copy link
Contributor

deech commented Oct 29, 2022

What happened?

The following code:

type
  Either[A,B] = object
    case kind:bool
    of false:
      b: B
    of true:
      a: A

  O = object of RootRef

proc oToEither(o:O):Either[O,void] =
  Either[O,void](kind:true,a: o)

discard oToEither(O())

fails to compile with:

/home/deech/.cache/nim/test_d/@mtest.nim.c:73:107: error: ‘union <anonymous>’ has no member named ‘_kind_1’; did you mean ‘_kind_2’?
   73 | static NIM_CONST tyObject_Either__D9a6Bf9aw0xiqmc0h0TIPoaw TM__ipcYmBC9bj9a1BW35ABoB1Kw_2 = {NIM_FALSE, {._kind_1 = {}}}
      |                                                                                                           ^~~~~~~
      |                                                                                                           _kind_2

Seems the default value of the Either tries to use a struct parameter that doesn't exist.

Nim Version

Nim Compiler Version 1.7.3 [Linux: amd64]
Compiled at 2022-10-29
Copyright (c) 2006-2022 by Andreas Rumpf

git hash: 534c97edc54ffb6d55baa5084f8c426a451c9244
active boot switches: -d:release

Current Standard Output Logs

No response

Expected Standard Output Logs

No response

Possible Solution

No response

Additional Information

No response

@deech
Copy link
Contributor Author

deech commented Oct 29, 2022

git bisect shows the problem is in this commit

@ringabout
Copy link
Member

ringabout commented Oct 30, 2022

I don't think so. It seems to be a pre-existing problem. It works with refc, not with ARC/ORC. I'm investigating it.

@arnetheduck
Copy link
Contributor

worked around with status-im/nim-stew#150

Araq added a commit that referenced this issue Nov 12, 2022
* Revert "fixes #20699; generate an empty struct for void type (#20790)"

This reverts commit 8fcb938.

* better fix [backport]
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
…g#20790)

* fixes nim-lang#20699; generate an empty struct for void type

* Add docs and test case.
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
…nim-lang#20806)

* Revert "fixes nim-lang#20699; generate an empty struct for void type (nim-lang#20790)"

This reverts commit 8fcb938.

* better fix [backport]
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
…g#20790)

* fixes nim-lang#20699; generate an empty struct for void type

* Add docs and test case.
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
…nim-lang#20806)

* Revert "fixes nim-lang#20699; generate an empty struct for void type (nim-lang#20790)"

This reverts commit 8fcb938.

* better fix [backport]
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.

3 participants