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

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

Open
jxy opened this issue Jun 30, 2017 · 4 comments
Open

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

jxy opened this issue Jun 30, 2017 · 4 comments

Comments

@jxy
Copy link
Contributor

jxy commented Jun 30, 2017

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.
@stale
Copy link

stale bot commented Aug 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Aug 4, 2020
@jxy
Copy link
Contributor Author

jxy commented Aug 4, 2020

It still results in the wrong C code.

@stale stale bot removed the stale Staled PR/issues; remove the label after fixing them label Aug 4, 2020
@jxy
Copy link
Contributor Author

jxy commented Jun 24, 2021

It still generates the wrong C code.

@bung87
Copy link
Collaborator

bung87 commented Nov 4, 2022

without the borrow, it result to same error, looks invalid to me, as F lose generic param.

type G[A] = object
  v:A
type F = distinct G
var g = G[int](v:1)
var f = F(g)

well after making this works, I starting to think below doesn't make much sense. for borrowing properties

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

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

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