8000 [fix] detect multiple versions of nject and fail - BACKPORT by muir · Pull Request #121 · muir/nject · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[fix] detect multiple versions of nject and fail - BACKPORT #121

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

Merged
merged 1 commit into from
Apr 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions nject.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type provider struct {
index int
fn interface{}
id int32
fatal error // set for delayed errors

// user annotations (match these in debug.go)
nonFinal bool
Expand Down Expand Up @@ -147,7 +148,13 @@ func newProvider(fn interface{}, index int, origin string) *provider {
if len(c.contents) == 1 {
return newProvider(c.contents[0], index, origin)
}
panic("Cannot turn Collection into a function")
return &provider{
origin: origin,
index: index,
fn: nil,
id: atomic.AddInt32(&idCounter, 1),
fatal: fmt.Errorf("cannot turn Collection into a function"),
}
}
return &provider{
origin: origin,
Expand Down Expand Up @@ -204,10 +211,14 @@ func (c Collection) characterizeAndFlatten(nonStaticTypes map[typeCode]bool) ([]
var mutated bool
for i := 0; i < len(c.contents); i++ {
fm := c.contents[i]
if fm.fatal != nil {
return nil, nil, fm.fatal
}
g, ok := fm.fn.(generatedFromInjectionChain)
if !ok {
continue
}
mutated = true
replacement, err := g.ReplaceSelf(
Collection{
name: "before",
Expand Down Expand Up @@ -299,7 +310,12 @@ func newCollection(name string, funcs ...interface{}) *Collection {
case provider:
contents = append(contents, v.renameIfEmpty(i, name))
default:
contents = append(contents, newProvider(fn, i, name))
p := newProvider(fn, i, name)
switch fmt.Sprintf("%T", fn) {
case "nject.Collection", "*nject.Collection", "nject.provider", "*nject.provider":
p.fatal = fmt.Errorf("multiple versions of nject detected -- not supported")
}
contents = append(contents, p)
}
}
return &Collection{
Expand Down
Loading
0