Skip to content

ARC: codegen bug, generated cpp doesn't compile #13029

Closed
@cooldome

Description

@cooldome

Test casem compile with nim cpp --gc:arc XXX

type
  TokenKind* = enum
    tkColon
    tkComma
    tkString
    tkNumber
    tkInt64
    tkIdent

  Token* = object
    case kind*: TokenKind
    of tkString: strVal*: string
    of tkNumber: numVal*: float
    of tkInt64: int64Val*: int64
    of tkIdent: ident*: string
    else: discard
    pos*: Natural

  BaseLexer* = object of RootObj
    input*: string
    pos*: Natural

  Json5Lexer* = object of BaseLexer

  JsonLexer* = object of BaseLexer
    allowComments*: bool
    allowSpecialFloats*: bool

  Lexer* = Json5Lexer | JsonLexer

  Parser[T: Lexer] = object
    l: T
    tok: Token
    allowTrailingComma: bool
    allowIdentifierObjectKey: bool

proc initJson5Lexer*(input: string): Json5Lexer =
  result.input = input

proc parseJson5*(input: string)  =
  var p = Parser[Json5Lexer](
    l: initJson5Lexer(input),
    allowTrailingComma: true,
    allowIdentifierObjectKey: true
  )

let x = "string"
parseJson5(x)

Generated cpp code fails compilation

Error: execution of an external compiler program 'g++.exe -c  -w -mno-ms-bitfields -w -fpermissive -mno-ms-bitfields   -IC:\Nim\lib -IC:\Nim -o "C:\nimcache\x1_d\@mx1.nim.cpp.o" "C:\nimcache\x1_d\@mx1.nim.cpp"' failed with exit code: 1

C:\nimcache\x1_d\@mx1.nim.cpp:114:147: error: could not convert '{{(& NTI__Tnwtohn42DJrL2jMvY4yjg_)}}' from '<brace-enclosed initializer list>' to 'tyObject_Json5Lexer__Tnwtohn42DJrL2jMvY4yjg'
 NIM_CONST tyObject_Parser__NcVQJhpnW9czydG9crD2Zbsg TM__ZPpeHLXgWrJ9bLTF8Y8dgsg_4 = {{{(&NTI__Tnwtohn42DJrL2jMvY4yjg_)}}, {}, NIM_FALSE, NIM_FALSE}

Example is from https://github.com/GULPF/samson library

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