Skip to content

Assigning descriminator field leads to internal assert with --gc:destructors #12821

@cooldome

Description

@cooldome

Compile with --gc:desctructors

type
  RefBaseObject* = ref object of RootObj
    case kind: bool
      of true: a: int
      of false: b: float

  MyRefObject = ref object of RefBaseObject
    x: float

let x = new(MyRefObject)
x.kind = false

Compiler is crashing with the following stack trace:

C:\Nim\compiler\nim.nim(106) nim
C:\Nim\compiler\nim.nim(83) handleCmdLine
C:\Nim\compiler\cmdlinehelper.nim(98) loadConfigsAndRunMainCommand
C:\Nim\compiler\main.nim(188) mainCommand
C:\Nim\compiler\main.nim(92) commandCompileToC
C:\Nim\compiler\modules.nim(144) compileProject
C:\Nim\compiler\modules.nim(85) compileModule
C:\Nim\compiler\passes.nim(210) processModule
C:\Nim\compiler\passes.nim(86) processTopLevelStmt
C:\Nim\compiler\cgen.nim(1880) myProcess
C:\Nim\compiler\ccgstmts.nim(1275) genStmts
C:\Nim\compiler\ccgexprs.nim(2618) expr
C:\Nim\compiler\ccgexprs.nim(2403) genStmtList
C:\Nim\compiler\ccgstmts.nim(1275) genStmts
C:\Nim\compiler\ccgexprs.nim(2666) expr
C:\Nim\compiler\ccgstmts.nim(1036) genTry
C:\Nim\compiler\ccgexprs.nim(2618) expr
C:\Nim\compiler\ccgexprs.nim(2403) genStmtList
C:\Nim\compiler\ccgstmts.nim(1275) genStmts
C:\Nim\compiler\ccgexprs.nim(2648) expr
C:\Nim\compiler\ccgstmts.nim(1267) genAsgn
C:\Nim\compiler\ccgstmts.nim(1238) asgnFieldDiscriminant
C:\Nim\compiler\ccgstmts.nim(1220) genCaseObjDiscMapping
C:\Nim\compiler\enumtostr.nim(79) genCaseObjDiscMapping
C:\Nim\lib\system\assertions.nim(27) failedAssertImpl
C:\Nim\lib\system\assertions.nim(20) raiseAssert
C:\Nim\lib\system\fatal.nim(39) sysFatal
Error: unhandled exception: C:\Nim\compiler\enumtostr.nim(79, 12) `subObj != nil`  [AssertionError]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions