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

C codegen issue with fieldPairs and Karax DSL #19069

Open
ajusa opened this issue Oct 29, 2021 · 0 comments
Open

C codegen issue with fieldPairs and Karax DSL #19069

ajusa opened this issue Oct 29, 2021 · 0 comments

Comments

@ajusa
Copy link

ajusa commented Oct 29, 2021

This snippet below fails to compile with gcc. I realize that this is probably adding quite a bit of complexity with the Karax DSL, but I'm not super sure how to minimize further. I was able to get it to fail in the playground as well, on 1.6 and 1.4.8

Example

import karax/[vdom, karaxdsl]
proc generateInputs[T](obj: T): VNode =
  buildHtml(tdiv):
    for name, placeholder in obj.fieldPairs:
      label:
        text name
        input(type="text", name=name, placeholder=placeholder)
type RegisterForm = object
  name: string
  email: string

echo $generateInputs(RegisterForm(name: "ajusa", email: "something@gmail.com"))

Current Output

Exists on devel as well

Hint: used config file '/home/ajusa/.choosenim/toolchains/nim-1.6.0/config/nim.cfg' [Conf]
Hint: used config file '/home/ajusa/.choosenim/toolchains/nim-1.6.0/config/config.nims' [Conf]
..................................................................................
CC: stdlib_digitsutils.nim
CC: stdlib_assertions.nim
CC: stdlib_dollars.nim
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: stdlib_math.nim
CC: stdlib_strutils.nim
CC: ../../.nimble/pkgs/karax-1.2.1/karax/vstyles.nim
CC: ../../.nimble/pkgs/karax-1.2.1/karax/vdom.nim
CC: ../../.nimble/pkgs/karax-1.2.1/karax/compact.nim
CC: testing.nim
/home/ajusa/.cache/nim/testing_d/@mtesting.nim.c: In function ‘generateInputs_testing_12’:
/home/ajusa/.cache/nim/testing_d/@mtesting.nim.c:192:66: error: redeclaration of ‘tmp_2’ with no linkage
  192 |         tyObject_VNodecolonObjectType___UzLz41HuYz7DVA9bD3pvmag* tmp_2;
      |                                                                  ^~~~~
/home/ajusa/.cache/nim/testing_d/@mtesting.nim.c:187:66: note: previous declaration of ‘tmp_2’ with type ‘tyObject_VNodecolonObjectType___UzLz41HuYz7DVA9bD3pvmag *’
  187 |         tyObject_VNodecolonObjectType___UzLz41HuYz7DVA9bD3pvmag* tmp_2;
      |                                                                  ^~~~~
/home/ajusa/.cache/nim/testing_d/@mtesting.nim.c:195:66: error: redeclaration of ‘tmp_3’ with no linkage
  195 |         tyObject_VNodecolonObjectType___UzLz41HuYz7DVA9bD3pvmag* tmp_3;
      |                                                                  ^~~~~
/home/ajusa/.cache/nim/testing_d/@mtesting.nim.c:190:66: note: previous declaration of ‘tmp_3’ with type ‘tyObject_VNodecolonObjectType___UzLz41HuYz7DVA9bD3pvmag *’
  190 |         tyObject_VNodecolonObjectType___UzLz41HuYz7DVA9bD3pvmag* tmp_3;
      |                                                                  ^~~~~
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/home/ajusa/.choosenim/toolchains/nim-1.6.0/lib -I/home/ajusa/Documents/example -o /home/ajusa/.cache/nim/testing_d/@mtesting.nim.c.o /home/ajusa/.cache/nim/testing_d/@mtesting.nim.c' failed with exit code: 1

Expected Output

Not sure, but it should be some HTML code. At the very least I should get a Nim compiler error or correct output.

$ nim -v
Nim Compiler Version 1.6.0 [Linux: amd64]
Compiled at 2021-10-19
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 727c6378d2464090564dbcd9bc8b9ac648467e38
active boot switches: -d:release

Might be related to #15637, it has a similar error message but the code is very different. Interestingly, if I make the type only have one field (such as name, without email) then it compiles and runs just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant