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

Invalid C++ code generation for assignment operator for generic types #10217

Open
BigEpsilon opened this issue Jan 6, 2019 · 3 comments
Open

Comments

@BigEpsilon
Copy link
Contributor

In certain situations, like in the following example, the compiler generates an invalid c++ code, where the parameters to the generated eq_XXX function have their template parameter missing.

Example

type 
    Vector*  {.importcpp: "std::vector", header: "vector".}[T] = object

proc initVector*[T](n: csize): Vector[T] 
    {.importcpp: "std::vector<'*0>(@)", header: "vector".}

proc `=`*[T](a: var Vector[T], b: Vector[T]) 
    {.importcpp: "operator=", header: "vector".}

var v1 = initVector[int](10)
var v2 : Vector[int]

v1 = v2

Current Output

Error: execution of an external compiler program 'g++ -c  -w -w -fpermissive  -I'/home/user/.choosenim/toolchains/nim-#devel/lib' -I/home/user/dev/nim/tests/play/src -o /home/user/.cache/nim/play_d/play_play.cpp.o /home/user/.cache/nim/play_d/play_play.cpp' failed with exit code: 1

/home/user/.cache/nim/play_d/play_play.cpp:27:70: error: variable or field ‘eqsink__9aTJ5qWKS9aEaagmcvJV6NvA’ declared void
 N_LIB_PRIVATE N_NIMCALL(void, eqsink__9aTJ5qWKS9aEaagmcvJV6NvA)(std::vector& dest, std::vector src);
                                                                      ^
/home/user/.cache/nim/play_d/play_play.cpp:27:76: error: missing template arguments before ‘&’ token
 N_LIB_PRIVATE N_NIMCALL(void, eqsink__9aTJ5qWKS9aEaagmcvJV6NvA)(std::vector& dest, std::vector src);

...

Expected Output

No compilation error

Possible Solution

If someone give me a hint to where to look in the compiler code, I may try to correct this bug.

Additional Information

nim --version

Nim Compiler Version 0.19.9 [Linux: amd64]
Compiled at 2019-01-03
Copyright (c) 2006-2018 by Andreas Rumpf

active boot switches: -d:release

@cooldome
Copy link
Member

cooldome commented Jan 6, 2019

Don't think your code is valid. You don't need to import cpp equal operator at all and the code should just work.

IMO, what should be done is the error message saying that = can't be an imported proc.

@BigEpsilon
Copy link
Contributor Author

I was not sure that the = operator was invoked for copy so I preferred to make it explicit.

I agree with you that if = cannot be imported we need to make it clear with an error message. (also forbid template =)

@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
@metagn metagn removed the stale Staled PR/issues; remove the label after fixing them label Sep 18, 2024
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