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

Combining object variants and inheritance leads to SIGSEGV during compilation #10033

Closed
liwt31 opened this issue Dec 18, 2018 · 3 comments

Comments

Projects
None yet
4 participants
@liwt31
Copy link

commented Dec 18, 2018

Object variants and inheritance are both good ideas and work quite well, but putting them together seems to lead to SIGSEGV during compilation. In my tests, if A is an object variant and B is inherited from A, then writing certain attributes of B (probably the discriminator) will result in SIGSEGV during compilation.

Example

type
  Token = enum
    Int,
    Float 

  Base = ref object of RootObj
    case token: Token
    of Int:
      bInt: int
    of Float:
      bFloat: float

  Child = ref object of Base

let c = new Child
c.token = Int

Current Output

$ nim c ghIssue.nim
Hint: used config file '/home/wtli/.choosenim/toolchains/nim-0.19.0/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: ghIssue [Processing]
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Expected Output

What I'm trying to do in the code example might be illegal (although I couldn't find any reference in the manual), but I don't think it should result in a segmentation fault.

Possible Solution

No idea. Thank you for your time for this!

Additional Information

Nim Compiler Version 0.19.0 [Linux: amd64]
Compiled at 2018-09-26
Copyright (c) 2006-2018 by Andreas Rumpf

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

@Araq

This comment has been minimized.

Copy link
Member

commented Dec 18, 2018

Strange bug, the compiler itself mixes both features freely.

@Araq Araq added the Showstopper label Dec 18, 2018

@deech

This comment has been minimized.

Copy link
Contributor

commented Dec 19, 2018

This seems to be some issue with ref's, this works:

type
  Token = enum
    Int,
    Float

  Base = object of RootObj
    case token: Token
    of Int:
      bInt: int
    of Float:
      bFloat: float

  Child = object of Base

let c = new Child
c.token = Int
@deech

This comment has been minimized.

Copy link
Contributor

commented Dec 19, 2018

This also works:

type
  Token = enum
    Int,
    Float

  Base = object of RootObj
    case token: Token
    of Int:
      bInt: int
    of Float:
      bFloat: float

  Child = ref object of Base

let c = new Child
c.token = Int

so there seems to be a problem with a ref object inheriting from another ref object.

@Araq Araq closed this in bdb6720 Dec 22, 2018

narimiran added a commit to narimiran/Nim that referenced this issue Dec 29, 2018

fixes nim-lang#10033 [backport]
(cherry picked from commit bdb6720)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.