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

GCC Error: redefinition of struct #13717

Open
Wh1teDuke opened this issue Mar 21, 2020 · 8 comments
Open

GCC Error: redefinition of struct #13717

Wh1teDuke opened this issue Mar 21, 2020 · 8 comments

Comments

@Wh1teDuke
Copy link
Contributor

Wh1teDuke commented Mar 21, 2020

Test

# M1.nim -------------------------
type TypeM1*  = object
# M2.nim -------------------------
import M1
var v: seq[ptr[seq[TypeM1]]] # No Error -> var v: seq[ptr[TypeM1]]
# M3.nim -------------------------
import M1, M2
type TypeM3[P] = P
var v: TypeM3[TypeM1]

nim c M3

Error

M3_d/@mM2.nim.c:72:8: error: redefinition ofstruct tyObject_TypeM1__rz9bu86TEcm9bQCKkG6au0GA72 | struct tyObject_TypeM1__rz9bu86TEcm9bQCKkG6au0GA {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
M3_d/@mM2.nim.c:68:8: note: originally defined here
   68 | struct tyObject_TypeM1__rz9bu86TEcm9bQCKkG6au0GA {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
M3_d/@mM2.nim.c:83:8: error: redefinition ofstruct tySequence__g11q9b2WUfHeKVRp9cimnrRQ83 | struct tySequence__g11q9b2WUfHeKVRp9cimnrRQ {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
M3_d/@mM2.nim.c:79:8: note: originally defined here
   79 | struct tySequence__g11q9b2WUfHeKVRp9cimnrRQ {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

>nim -v
Nim Compiler Version 1.1.1 [Linux: i386]
Compiled at 2020-03-21
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 586ebb090b3c7fd2fedbaa24e2b00b7caae4e009
active boot switches: -d:release
@timotheecour
Copy link
Member

@Wh1teDuke this bug is not actionable, please provide a minimized reproducing example. Yes, this can take some efforts sometimes, but it's the only way, until #8276 is fixed

@Wh1teDuke
Copy link
Contributor Author

@Wh1teDuke this bug is not actionable, please provide a minimized reproducing example. Yes, this can take some efforts sometimes, but it's the only way, until #8276 is fixed

Sadly I can't do that. I don't remember why but some code change made the bug disappear. I always try to isolate the code, but this time I had no success. Don't know what really triggered it. Sorry I cannot be of any help.

@Araq
Copy link
Member

Araq commented Mar 24, 2020

Closing for now, there is also a better name mangler in the works that could fix it.

@Araq Araq closed this as completed Mar 24, 2020
@Wh1teDuke
Copy link
Contributor Author

Wh1teDuke commented Mar 24, 2020

Well, unfortunately I stumbled across this bug again, but this time I managed to reduce the code:

# M1.nim ------------------
type Bar*  = object
# M2.nim ------------------
import M1
import std/sets
var foo: HashSet[Bar]
# M3.nim ------------------
import M1, M2
type Type1[P]  = P
type Type2     = ptr[Type1[Bar]]

nim c M3:

.cache/nim/M3_d/stdlib_sets.nim.c:74:8: error: redefinition ofstruct tyObject_Bar__Wcc5gWFgEqZSm9aH8GC9aOyg74 | struct tyObject_Bar__Wcc5gWFgEqZSm9aH8GC9aOyg {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.cache/nim/M3_d/stdlib_sets.nim.c:54:8: note: originally defined here
   54 | struct tyObject_Bar__Wcc5gWFgEqZSm9aH8GC9aOyg {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.cache/nim/M3_d/stdlib_sets.nim.c:85:8: error: redefinition ofstruct tySequence__3Z4QiwjOXcnT0SN6DgMBqg85 | struct tySequence__3Z4QiwjOXcnT0SN6DgMBqg {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.cache/nim/M3_d/stdlib_sets.nim.c:81:8: note: originally defined here
   81 | struct tySequence__3Z4QiwjOXcnT0SN6DgMBqg {
      |     

@Araq Araq reopened this Mar 24, 2020
@timotheecour
Copy link
Member

thanks; @Wh1teDuke if you want to help fix this issue, one way to do that would be to further reduce by removing external module dependency (std/sets)
maybe related past fixed issues:
#5170
#12704

@Wh1teDuke
Copy link
Contributor Author

thanks; @Wh1teDuke if you want to help fix this issue, one way to do that would be to further reduce by removing external module dependency (std/sets)
maybe related past fixed issues:
#5170
#12704

# M1.nim -------------------------
type TypeM1*  = object
# M2.nim -------------------------
import M1
var v: seq[ptr[seq[TypeM1]]] # No Error -> var v: seq[ptr[TypeM1]]
# M3.nim -------------------------
import M1, M2
type TypeM3[P] = P
var v: TypeM3[TypeM1]

I tried different combinations of generics/imports, so far this is the smallest combination.

@Wh1teDuke Wh1teDuke changed the title error: redefinition of struct GCC Error: redefinition of struct Mar 25, 2020
@krux02
Copy link
Contributor

krux02 commented Mar 27, 2020

The question is, is type TypeM3[P] = P even valid code? If not, I think this is an easy fix in the sem checker.

@Araq
Copy link
Member

Araq commented Mar 27, 2020

It's valid code.

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

4 participants