Skip to content

Generator can create duplicate RegisterSchema functions #490

Closed
@Hoops

Description

@Hoops

After the change for #479, if you have multiple capnp files in a package, e.g.

$ cat book.capnp
using Go = import "/go.capnp";
@0x85d3acc39d94e0f8;
$Go.package("books");
$Go.import("foo/books");

struct Book {
    title @0 :Text;
    # Title of the book.

    pageCount @1 :Int32;
    # Number of pages in the book.
}

and

$ cat book2.capnp
using Go = import "/go.capnp";
@0x86115605f6b5e399;
$Go.package("books");
$Go.import("foo/books");

struct Book2 {
    title @0 :Text;
    # Title of the book.

    pageCount @1 :Int32;
    # Number of pages in the book.
}

then

$ capnp compile -I$HOME/go/pkg/mod/capnproto.org/go/capnp/v3@v3.0.0-alpha.24/std -ogo:. *.capnp 
$ go mod init books; go mod tidy
go: creating new go.mod: module books
go: to add module requirements and sums:
	go mod tidy
go: finding module for package capnproto.org/go/capnp/v3/schemas
go: finding module for package capnproto.org/go/capnp/v3/encoding/text
go: finding module for package capnproto.org/go/capnp/v3
go: found capnproto.org/go/capnp/v3 in capnproto.org/go/capnp/v3 v3.0.0-alpha.25
go: found capnproto.org/go/capnp/v3/encoding/text in capnproto.org/go/capnp/v3 v3.0.0-alpha.25
go: found capnproto.org/go/capnp/v3/schemas in capnproto.org/go/capnp/v3 v3.0.0-alpha.25
$ go build ./...
# books
./book2.capnp.go:113:6: RegisterSchema redeclared in this block
	./book.capnp.go:113:6: other declaration of RegisterSchema

There will be duplicate functions in the same package. Maybe the register function needs to be generated in a separate file per-package with one RegisterSchema for all?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions