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

Redefinition and usage of ref type in different scopes leads to invalid c code #17666

Closed
KnorrFG opened this issue Apr 7, 2021 · 1 comment · Fixed by #17710
Closed

Redefinition and usage of ref type in different scopes leads to invalid c code #17666

KnorrFG opened this issue Apr 7, 2021 · 1 comment · Fixed by #17710

Comments

@KnorrFG
Copy link

KnorrFG commented Apr 7, 2021

It seems that when you define a type with different fields in two different scopes, and instantiate it in both scopes, and accedss a field in the second defintion, that didnt exist in the first definition, the generated c-code will be invalid.

Compiling this:

block:
    type Foo = ref object
    echo Foo().repr
block:
    type Foo = ref object
      field: int
    echo Foo().field

will result in:

[I] felix@rzbl ~/tmp> nim c nimbug.nim
Hint: used config file '/home/felix/git/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/felix/git/Nim/config/config.nims' [Conf]
....                                                                                                        
CC: stdlib_assertions.nim
CC: stdlib_dollars.nim
CC: stdlib_formatfloat.nim
CC: stdlib_io.nim
CC: stdlib_system.nim
CC: nimbug.nim
/home/felix/.cache/nim/nimbug_d/@mnimbug.nim.c: In function ‘NimMainModule’:
/home/felix/.cache/nim/nimbug_d/@mnimbug.nim.c:191:30: error: ‘tyObject_FoocolonObjectType___fGcm43VB58lQvE79caF19bjQ’ {aka ‘struct tyObject_FoocolonObjectType___fGcm43VB58lQvE79caF19bjQ’} has no member named ‘field’  191 |   T5_[0] = nimIntToStr((*T6_).field);
      |                              ^
Error: execution of an external compiler program 'gcc -c  -w -fmax-errors=3   -I/home/felix/git/Nim/lib -I/home/felix/tmp -o /home/felix/.cache/nim/nimbug_d/@mnimbug.nim.c.o /home/felix/.cache/nim/nimbug_d/@mnimbug.nim.c' failed with exit code: 1

Also:

[I] felix@rzbl ~/tmp> nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-04-04
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 97764c8dc91081875f57029ae3f72d3a503f5e45
active boot switches: -d:release
@ringabout
Copy link
Member

Duplicate of #15526

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

Successfully merging a pull request may close this issue.

2 participants