Skip to content

Codegen bug with exportc and case objects #13281

@cooldome

Description

@cooldome

Test case

type
  Helper* {.exportc: "PublicHelper".} = object
    case isKind: bool
      of true:
        formatted: string
      of false:
        parsed1: string
        parsed2: string

proc test(c: Helper): string =
  c.formatted

echo test(Helper(isKind: true, formatted: "ok"))

On latest Nim generated C fails to compile with error:

Error: execution of an external compiler program 'gcc.exe -c  -w -mno-ms-bitfields   -IC:\Nim\lib -IC:\Nim -o "C:\t1_d\@mt1.nim.c.o" "C:\t1_d\@mt1.nim.c"' failed with exit code: 1

C:\t1_d\@mt1.nim.c: In function 'test__cf7ypsLB70bFkcUMOU1MAg':
C:\t1_d\@mt1.nim.c:120:23: error: 'PublicHelper' {aka 'struct PublicHelper'} has no member named 'formatted'
  result = copyString(c.formatted);

Compiles fine without exportc pragma

I have a fix

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