Skip to content

Borrow . in distinct generic types generates bad c code #6039

Open
@jxy

Description

@jxy

With the code

type G[A] = object
  v:A
type F {.borrow: `.`.} = distinct G

var g = G[int](v:1)
var f = F(g)
echo g.v
echo f.v

using compiler

Nim Compiler Version 0.17.1 (2017-06-30) [MacOSX: amd64]
Copyright (c) 2006-2017 by Andreas Rumpf

git hash: 4de989d1c5e69393e3ac14fa0516203d0d06773a
active boot switches: -d:release

The c compiler complaints about the bad c code.

$ nim c t.nim    
Hint: used config file '/Users/jin/pkg/src/Nim-devel/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: t [Processing]
CC: tmp_t
CC: stdlib_system
Error: execution of an external compiler program 'clang -c  -w  -I/Users/jin/pkg/src/Nim-devel/lib -o /Users/jin/tmp/nimcache/tmp_t.o /Users/jin/tmp/nimcache/tmp_t.c' failed with exit code: 1

/Users/jin/tmp/nimcache/tmp_t.c:133:27: error: assigning to 'G_No3p5m0ZKtGo56MF2jraGw' (aka 'struct G_No3p5m0ZKtGo56MF2jraGw') from incompatible type 'G_jdHvP31usBP9cMk9aMPWrjVA' (aka 'struct G_jdHvP31usBP9cMk9aMPWrjVA')
        f_cJwUcqUYRCv7qhxy0Ko3Bg = g_gzmpjI9cnOVgSdyajRkwuzw;
                                 ^ ~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions