Skip to content

Constructor to global variable in converter generates illegal c code #4594

Open
@Tarmean

Description

@Tarmean

This is a tad difficult to explain so I am going to give examples. This generates illegal c code:

type
  Inner =  object
    foo: string
converter toString(i: int): string =
  var g{.global.} = Inner(foo: $i)
var s: string = 4

src\nimcache\converter_test.c: In function 'converter_testInit000':
src\nimcache\converter_test.c:354:30: error: 'i0' undeclared (first use in this function)
LOC100001.foo = nimIntToStr(i0);
^
src\nimcache\converter_test.c:354:30: note: each undeclared identifier is reported only once for each function it appears in

In contrast this does compile and work as expected:

type
  Inner =  object
    foo: string
converter toString(i: int): string =
  var g{.global.} : Inner
   g.foo = $i
var s: string = 4

When the string is constant, say Inner(foo: "bar"), or the converter is invoked explicitely the program also works.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions