Type, declared in generic proc body, leads to incorrect codegen (sighashes regression) #5147

nigredo-tori opened this Issue Dec 26, 2016 · 0 comments


None yet

1 participant



proc foo[T](t: T) =
  type Wrapper = object
    get: T
  let w = Wrapper(get: t)
  echo w.get


This fails to compile with both C and C++ backends:

Error: execution of an external compiler program 'gcc -c  -w  -I/home/dmitry/work/nim/lib -o /home/dmitry/work/tmp/nimcache/dups_test_union.o /home/dmitry/work/tmp/nimcache/dups_test_union.c' failed with exit code: 1

/home/dmitry/work/tmp/nimcache/dups_test_union.c: In function ‘foo_txkHN9aXCFrrufpg9bE5Np1A’:
/home/dmitry/work/tmp/nimcache/dups_test_union.c:97:35: error: invalid type argument of ‘->’ (have ‘NI {aka long long int}’)
  printf("%s\012", w0.get? (w0.get)->data:"nil");

It seems that, for both instantiations of the proc, the type is mapped to the same underlying struct, generated for the first instantiation.

Tested for: e182873
Bisect points to: 860cbd3

@Araq Araq added a commit that closed this issue Dec 29, 2016
@Araq Araq fixes #5147 4104ee1
@Araq Araq closed this in 4104ee1 Dec 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment