@@ -18,6 +18,7 @@ type provider struct {
1818 index int
1919 fn interface {}
2020 id int32
21+ fatal error // set for delayed errors
2122
2223 // user annotations (match these in debug.go)
2324 nonFinal bool
@@ -147,7 +148,13 @@ func newProvider(fn interface{}, index int, origin string) *provider {
147148 if len (c .contents ) == 1 {
148149 return newProvider (c .contents [0 ], index , origin )
149150 }
150- panic ("Cannot turn Collection into a function" )
151+ return & provider {
152+ origin : origin ,
153+ index : index ,
154+ fn : nil ,
155+ id : atomic .AddInt32 (& idCounter , 1 ),
156+ fatal : fmt .Errorf ("cannot turn Collection into a function" ),
157+ }
151158 }
152159 return & provider {
153160 origin : origin ,
@@ -204,10 +211,14 @@ func (c Collection) characterizeAndFlatten(nonStaticTypes map[typeCode]bool) ([]
204211 var mutated bool
205212 for i := 0 ; i < len (c .contents ); i ++ {
206213 fm := c .contents [i ]
214+ if fm .fatal != nil {
215+ return nil , nil , fm .fatal
216+ }
207217 g , ok := fm .fn .(generatedFromInjectionChain )
208218 if ! ok {
209219 continue
210220 }
221+ mutated = true
211222 replacement , err := g .ReplaceSelf (
212223 Collection {
213224 name : "before" ,
@@ -299,7 +310,12 @@ func newCollection(name string, funcs ...interface{}) *Collection {
299310 case provider :
300311 contents = append (contents , v .renameIfEmpty (i , name ))
301312 default :
302- contents = append (contents , newProvider (fn , i , name ))
313+ p := newProvider (fn , i , name )
314+ switch fmt .Sprintf ("%T" , fn ) {
315+ case "nject.Collection" , "*nject.Collection" , "nject.provider" , "*nject.provider" :
316+ p .fatal = fmt .Errorf ("multiple versions of nject detected -- not supported" )
317+ }
318+ contents = append (contents , p )
303319 }
304320 }
305321 return & Collection {
0 commit comments