nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: uber-go/dig
Pull request #344 (2022-07-14 22:32:39)

Fix issue with wrong invoke for multiple private providers
This fixes issue #343 - we check if the value can be provided in each scope from current to root, instead of first searching for pre built ones in all scopes.

CLAassistant: [![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/uber-go/dig?pullRequest=344) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our [Contributor License Agreement](https://cla-assistant.io/uber-go/dig?pullRequest=344) before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/uber-go/dig?pullRequest=344) it.</sub>

Patch:
diff --git a/param.go b/param.go
index 54c45be..5e769b0 100644
--- a/param.go
+++ b/param.go
@@ -213,6 +213,11 @@ func (ps paramSingle) getValue(c containerStore) (reflect.Value, bool) {
 		if v, ok := c.getValue(ps.Name, ps.Type); ok {
 			return v, ok
 		}
+		// If this scope can provide a value, we will build it instead of use upstream, since this
+		// is the closest provider
+		if providers := c.getValueProviders(ps.Name, ps.Type); len(providers) > 0 {
+			return _noValue, false
+		}
 	}
 	return _noValue, false
 }


Test patch:
diff --git a/scope_test.go b/scope_test.go
index 3710f75..d5e33ed 100644
--- a/scope_test.go
+++ b/scope_test.go
@@ -71,6 +71,24 @@ func TestScopedOperations(t *testing.T) {
 		assert.Error(t, c.Invoke(useB))
 	})
 
+	t.Run("private provides doesn't depend on invoke order", func(t *testing.T) {
+		c := digtest.New(t)
+		child := c.Scope("child")
+
+		c.RequireProvide(func() string { return "container" })
+		child.RequireProvide(func() string { return "child" })
+
+		verifyContainerStr := func(s string) {
+			assert.Equal(t, "container", s)
+		}
+		verifyChildStr := func(s string) {
+			assert.Equal(t, "child", s)
+		}
+
+		c.RequireInvoke(verifyContainerStr)
+		child.RequireInvoke(verifyChildStr)
+	})
+
 	t.Run("provides to top-level Container propogates to all scopes", func(t *testing.T) {
 		type A struct{}