Skip to content

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

Open
@BigEpsilon

Description

@BigEpsilon

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

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