Nim: GCC Error: redefinition of struct

Created on 21 Mar 2020  Â·  8Comments  Â·  Source: nim-lang/Nim

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 of ‘struct tyObject_TypeM1__rz9bu86TEcm9bQCKkG6au0GA’
   72 | 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 of ‘struct tySequence__g11q9b2WUfHeKVRp9cimnrRQ’
   83 | 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
Type sections

Most helpful comment

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 of ‘struct tyObject_Bar__Wcc5gWFgEqZSm9aH8GC9aOyg’
   74 | 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 of ‘struct tySequence__3Z4QiwjOXcnT0SN6DgMBqg’
   85 | struct tySequence__3Z4QiwjOXcnT0SN6DgMBqg {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.cache/nim/M3_d/stdlib_sets.nim.c:81:8: note: originally defined here
   81 | struct tySequence__3Z4QiwjOXcnT0SN6DgMBqg {
      |     

All 8 comments

@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 https://github.com/nim-lang/Nim/issues/8276 is fixed

@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.

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

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 of ‘struct tyObject_Bar__Wcc5gWFgEqZSm9aH8GC9aOyg’
   74 | 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 of ‘struct tySequence__3Z4QiwjOXcnT0SN6DgMBqg’
   85 | struct tySequence__3Z4QiwjOXcnT0SN6DgMBqg {
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.cache/nim/M3_d/stdlib_sets.nim.c:81:8: note: originally defined here
   81 | struct tySequence__3Z4QiwjOXcnT0SN6DgMBqg {
      |     

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:
https://github.com/nim-lang/Nim/issues/5170
https://github.com/nim-lang/Nim/issues/12704

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.

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

It's valid code.

Was this page helpful?
0 / 5 - 0 ratings