objectbox-go: Can not generate struct with relation

When generating the following struct

type Progress struct {
	Id             uint64
	Show           *shows.Show `objectbox:"link"`
}

which has a relation to the show struct, i manage the get the following error:

Generating ObjectBox bindings for internal/<pgk>/object.go
can't prepare bindings for internal/<pgk>/object.go: error running type-check: internal/<pgk>/object.go:7:2: could not import og/internal/showsrss (type-checking package "og/internal/showsrss" failed (/Users/ogkevin/projects/OGKevin/og/internal/showsrss/entires_api.go:8:2: could not import github.com/objectbox/objectbox-go/objectbox (type-checking package "github.com/objectbox/objectbox-go/objectbox" failed (/Users/ogkevin/go/pkg/mod/github.com/objectbox/objectbox-go@v1.0.0/objectbox/model.go:30:2: could not import github.com/objectbox/objectbox-go/internal/generator (go/build: importGo github.com/objectbox/objectbox-go/internal/generator: exit status 1
go: finding github.com/objectbox/objectbox-go/internal/generator latest
go: finding github.com/objectbox/objectbox-go/internal latest
can't load package: package github.com/objectbox/objectbox-go/internal/generator: unknown import path "github.com/objectbox/objectbox-go/internal/generator": cannot find module providing package github.com/objectbox/objectbox-go/internal/generator

it leads me to believe that there is something wrong with the object box package? I tried diging into the code but its a little cryptic and could not follow the logic of typing checking.

If i remove the link between the 2, the generator is able to generate without problems. Any ideas ?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15

Most upvoted comments

TLDR; Generator runs a Go built-in type-checker when it needs to discover info about unknown types. Having models in a separate package, without unnecessary dependencies is the easiest way to 1. avoid unrelated type-checker errors; 2. keep the generator fast (because it doesn’t have to go through the dependencies).


If the generator encounters a field with a non-trivial type (e.g. another struct, a named type/type alias, etc), it invokes Go built-in type checker which provides type information. The thing is there are no means to limit the scope on which the type checker runs - we just give it the package and it goes around to any depth it needs (unfortunately). Therefore, when there are errors, the type checker returns those. Recently, I’ve noticed that even if the type checker returned errors, it tried to continue analyzes even in case of an error so the relevant type we were actually looking for may still be resolved just find. That should help with your situation as well.

As for the go.sum writing - that seems to be a side-effect of running the built-in type-checker. It seems it does automatically some staff that the go-tool usually does. The gomissing project didn’t include go.sum at that version even though it should have. I’ll try to isolate the issue and see if it can be reported at https://github.com/golang. There seem to be some related issues though https://github.com/golang/go/issues/30185 and https://github.com/golang/go/issues/27300