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

Codegen bug with proc with union arguments with default values #13944

Open
ghost opened this issue Apr 10, 2020 · 2 comments
Open

Codegen bug with proc with union arguments with default values #13944

ghost opened this issue Apr 10, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented Apr 10, 2020

This code errors at C compilation step

Example

proc myMegaProc(a: string, b: seq[string] | seq[bool] = @[]) = 
  when a is string:
    discard
  elif b is seq[string]:
    for x in b:
      echo x

myMegaProc("hello")

Current Output

CC: hello.nim
In file included from /home/dian/.cache/nim/hello_d/@mhello.nim.c:9:
/home/dian/.cache/nim/hello_d/@mhello.nim.c:82:31: error: conflicting types for 'myMegaProc__lWBnHp6d1v1cWhDKZfWHiQ'
   82 | N_LIB_PRIVATE N_NIMCALL(void, myMegaProc__lWBnHp6d1v1cWhDKZfWHiQ)(NimStringDesc* a, tySequence__77YVzYb2AOu2vP0iI0b8Dw* b) {
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dian/.nim/lib/nimbase.h:250:44: note: in definition of macro 'N_NIMCALL'
  250 | #  define N_NIMCALL(rettype, name) rettype name /* no modifier */
      |                                            ^~~~
/home/dian/.cache/nim/hello_d/@mhello.nim.c:44:31: note: previous declaration of 'myMegaProc__lWBnHp6d1v1cWhDKZfWHiQ' was here
   44 | N_LIB_PRIVATE N_NIMCALL(void, myMegaProc__lWBnHp6d1v1cWhDKZfWHiQ)(NimStringDesc* a, TGenericSeq* b);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dian/.nim/lib/nimbase.h:250:44: note: in definition of macro 'N_NIMCALL'
  250 | #  define N_NIMCALL(rettype, name) rettype name /* no modifier */
      |                                            ^~~~
Error: execution of an external compiler program 'gcc -c  -w   -I/home/dian/.nim/lib -I/home/dian/Projects/skidfix -o /home/dian/.cache/nim/hello_d/@mhello.nim.c.o /home/dian/.cache/nim/hello_d/@mhello.nim.c' failed with exit code: 1

Expected Output

Compiler error message

Additional Information

  • I consider this to be low-priority because the code is not valid Nim anyway
$ nim -v
Nim Compiler Version 1.3.1 [Linux: amd64]
Compiled at 2020-04-09
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: cc3f5d21b249fe8f96f61369e53e794bf34e65a5
active boot switches: -d:release
@ghost ghost changed the title Low-priority codegen bug Codegen bug with proc with union arguments with default values Apr 10, 2020
@ghost ghost added the Code Generation label Jul 25, 2020
@metagn
Copy link
Collaborator

metagn commented Aug 27, 2024

Similar to #4858 but with empty collection literals instead of int literal

@metagn
Copy link
Collaborator

metagn commented Oct 2, 2024

Now gives

Error: internal error: cannot map the empty seq type to a C type

It should still give a proper error though

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

No branches or pull requests

1 participant