Skip to content

Code generation can result in functions being included more than once #51

@esp1

Description

@esp1

In situations where the same function is referenced in multiple files, ferret code generation can result in the function definitions being included multiple times. In the following example the bar function is called directly in main, and also indirectly via the foo function:

main.clj:

(require 'foo)
(require 'bar)

(foo/foo)
(bar/bar 0)

foo.clj:

(require 'bar)

(defn foo []
  (bar/bar 1))

bar.clj

(defn bar [x]
  x)

If you compile main.clj with ferret, it will emit a .cpp file with multiple definitions of the bar function. Trying to compile that .cpp file will result in these errors:

src/main.cpp:2537:7: error: redefinition of 'class main::bar_bar'
 class bar_bar {
       ^~~~~~~
src/main.cpp:2527:7: note: previous definition of 'class main::bar_bar'
 class bar_bar {
       ^~~~~~~
src/main.cpp:2564:12: error: redefinition of 'ferret::var main::bar_bar::invoke(ferret::ref) const'
 inline var bar_bar::invoke(ref _args_) const {
            ^~~~~~~
src/main.cpp:2551:12: note: 'ferret::var main::bar_bar::invoke(ferret::ref) const' previously defined here
 inline var bar_bar::invoke(ref _args_) const {
            ^~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions