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

`openArray` generates incorrect C code with "incomplete type" #9578

Closed
jxy opened this issue Oct 30, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@jxy
Copy link
Contributor

commented Oct 30, 2018

openArray[T] generates incorrect C code, if the containing module does not use T directly.

Example

This is the t_openarray.nim

import t
proc testOpenArray*(x:var openArray[mytype]) = f(x[0].addr)

This is the t.nim

type mytype* = object
  v:int
proc f*(x:ptr mytype) = x.v = -1

import t_openarray

func g(x:int):mytype = mytype(v:x)
var x = @[1.g,2.g,3.g]
testOpenArray(x)
echo x

Current Output

$ nim c t   
Hint: used config file '/usr/home/jin/src/Nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: t [Processing]
Hint: t_openarray [Processing]
CC: t_openarray
Error: execution of an external compiler program 'clang -c  -w -march=native  -I/usr/home/jin/src/Nim/lib -o /home/jin/.cache/nim/t_d/t_openarray.c.o /home/jin/.cache/nim/t_d/t_openarray.c' failed with exit code: 1

/home/jin/.cache/nim/t_d/t_openarray.c:63:30: error: subscript of pointer to incomplete type 'tyObject_mytype_GT9au9avkp87mWgJ7iYs2Q8w' (aka 'struct tyObject_mytype_GT9au9avkp87mWgJ7iYs2Q8w')
        f_gHtXMuYjDwRnyeN7HbPJpg((&x[((NI) 0)]));
                                   ~^
/home/jin/.cache/nim/t_d/t_openarray.c:24:16: note: forward declaration of 'struct tyObject_mytype_GT9au9avkp87mWgJ7iYs2Q8w'
typedef struct tyObject_mytype_GT9au9avkp87mWgJ7iYs2Q8w tyObject_mytype_GT9au9avkp87mWgJ7iYs2Q8w;
               ^
1 error generated.

There is only this typedef in the generated C file, but the struct tyObject_mytype_GT9au9avkp87mWgJ7iYs2Q8w is never defined anywhere.

@Araq

This comment has been minimized.

Copy link
Member

commented Oct 30, 2018

Caused by the cyclic module dependencies?

@jxy

This comment has been minimized.

Copy link
Contributor Author

commented Oct 30, 2018

Caused by the cyclic module dependencies?

No.

Example without circular dependencies

File t_types.nim

type mytype* = object
  v:int
proc f*(x:ptr mytype) = x.v = -1
func g*(x:int):mytype = mytype(v:x)

File t_openarray.nim

import t_types
proc testOpenArray*(x:var openArray[mytype]) = f(x[0].addr)

File t.nim

import t_types
import t_openarray

var x = @[1.g,2.g,3.g]
testOpenArray(x)
echo x

Compiler Output

$ nim c t            
Hint: used config file '/usr/home/jin/src/Nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: t [Processing]
Hint: t_types [Processing]
Hint: t_openarray [Processing]
CC: t
CC: stdlib_system
CC: t_types
CC: t_openarray
Error: execution of an external compiler program 'clang -c  -w -march=native  -I/usr/home/jin/src/Nim/lib -o /home/jin/.cache/nim/t_d/t_openarray.c.o /home/jin/.cache/nim/t_d/t_openarray.c' failed with exit code: 1

/home/jin/.cache/nim/t_d/t_openarray.c:63:30: error: subscript of pointer to incomplete type 'tyObject_mytype_0FqG1cvbI4x6hhsVmfBaCA' (aka 'struct tyObject_mytype_0FqG1cvbI4x6hhsVmfBaCA')
        f_KM3qUDczLt1zZbqx4OA5zA((&x[((NI) 0)]));
                                   ~^
/home/jin/.cache/nim/t_d/t_openarray.c:24:16: note: forward declaration of 'struct tyObject_mytype_0FqG1cvbI4x6hhsVmfBaCA'
typedef struct tyObject_mytype_0FqG1cvbI4x6hhsVmfBaCA tyObject_mytype_0FqG1cvbI4x6hhsVmfBaCA;
               ^
1 error generated.

@krux02 krux02 added the Codegen label Oct 31, 2018

jcosborn added a commit to jcosborn/Nim that referenced this issue May 5, 2019

@Araq Araq closed this in b1091f8 May 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.